Snapping Windows 4 to a screen with the mouse, one at a time

烈酒焚心 提交于 2019-12-12 02:53:46

问题


I want to snap windows to a corner (quarter) of a screen by right clicking before letting go of the window being moved by the mouse. I'm currently struggling with getting the active window to move. For the LEFT screen, top left position I can get Notepad to move, but it snaps back to its previous position when the mouse button is released; and I have to call it out by name--I want it to work with any active window. Thoughts?

~Lbutton & ~Rbutton::

CoordMode,Mouse,Screen  ;mouse position relative to the screen
MouseGetPos,Xpos,Ypos   ;get mouse position coordinates
;WinGet, active_id, ID, A
;msgbox %Xpos%,%Ypos%   ;show the saved mouse coordinates 

RIGHT_height=537
RIGHT_width=848
RIGHT_leftpos=1680
RIGHT_rightpos=2523
RIGHT_toppos=-70
RIGHT_vp=460    

LEFT_height=518
LEFT_width=847
LEFT_leftpos=-8
LEFT_rightpos=834
LEFT_toppos=-10
LEFT_vp=503

;LEFT SCREEN
if (Xpos < LEFT_rightpos and ypos < LEFT_vp) {  ;LEFT top left
    WinMove,Untitled - Notepad,,%LEFT_leftpos%,%LEFT_toppos%,%LEFT_width%,%LEFT_height%

}

if (Xpos > LEFT_rightpos and Xpos < 1680 and ypos < LEFT_vp) {  ;LEFT top right
    MsgBox LEFT top right
}

if (Xpos < LEFT_rightpos and Xpos < 1680 and ypos > LEFT_vp) {  ;LEFT top right
msgbox LEFT Bottom Left
}

if (Xpos > LEFT_rightpos and Xpos < 1680 and ypos > LEFT_vp) {  ;LEFT top right
msgbox LEFT Bottom Right
}

;RIGHT SCREEN
if (Xpos < RIGHT_rightpos and Xpos >= 1680 and ypos < RIGHT_vp) {   ;RIGHT top left
msgbox RIGHT Top Left
}

if (Xpos > RIGHT_rightpos and Xpos >= 1680 and ypos < RIGHT_vp) {   ;RIGHT top right
msgbox RIGHT Top Right
}

if (Xpos < RIGHT_rightpos and Xpos >= 1680 and ypos > RIGHT_vp) {   ;RIGHT top right
msgbox RIGHT Bottom Left
}

if (Xpos > RIGHT_rightpos and Xpos >= 1680 and ypos > RIGHT_vp) {   ;RIGHT top right
msgbox RIGHT Bottom Right
}

return


回答1:


You need to add

Send, {LButton Up}

in your code. This prevents the LButton being held from taking over the window when the hotkey's actions are complete.

In order to use WinMove with the ahk_id you must put this in the WinMove command. See below.

~LButton & ~RButton::
    CoordMode,Mouse,Screen 
    MouseGetPos,Xpos,Ypos   
    WinGet, active_id, ID, A ; use active_id in WinMove
    Send, {LButton Up} ; Prevents window from snapping back


    RIGHT_height=537
    RIGHT_width=848
    RIGHT_leftpos=1680
    RIGHT_rightpos=2523
    RIGHT_toppos=-70
    RIGHT_vp=460    

    LEFT_height=518
    LEFT_width=847
    LEFT_leftpos=-8
    LEFT_rightpos=834
    LEFT_toppos=-10
    LEFT_vp=503

    ;LEFT SCREEN
    if (Xpos < LEFT_rightpos and ypos < LEFT_vp) {  ;LEFT top left
        WinMove,ahk_id %active_id%,,%LEFT_leftpos%,%LEFT_toppos%,%LEFT_width%,%LEFT_height%

    }

    if (Xpos > LEFT_rightpos and Xpos < 1680 and ypos < LEFT_vp) {  ;LEFT top right
        MsgBox LEFT top right
    }

    if (Xpos < LEFT_rightpos and Xpos < 1680 and ypos > LEFT_vp) {  ;LEFT top right
    msgbox LEFT Bottom Left
    }
Return


来源:https://stackoverflow.com/questions/18644176/snapping-windows-4-to-a-screen-with-the-mouse-one-at-a-time

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!