; ; mg.ahk - Mouse gestures with right button. ; ; Jason Hood, 15 August to 9 September, 2004. ; ; Adapted from mousegesture.ahk from: ; http://lukewarm.s41.xrea.com/AutoHotkey/myscripts/ ; ;#NoTrayIcon Menu Tray, Tip, Mouse Gestures SetMouseDelay -1 SetDefaultMouseSpeed 0 mg_active = 0 timeout = 50 ; approx. half a second sensitivity = 50 ; this many pixels required before being accepted ; Show a tooltip indicating the current gesture; uncomment to hide it. ;mg_show = hide ; Ignore unknown gestures (no right click); uncomment to do the click. ;mg_rclick = yes ; Define the recognised gestures (each of these should have an _Action label). ; Any number of directions is allowed, so, for example, an "S" (or "5") gesture ; could be created with "LDRDL". gestures = -L-R-U-D-LR-RL-DU-LD-UR-RD-UL-RU-DL-LU-DR-UD- ; Window titles to exclude. excluded = Pixia ; Window titles which automatically disable the gestures (it can't quite handle ; simultaneous left/right presses correctly). disabled = Minesweeper,Cheat Mine ; Initialise variables for the actions and exit. goto action_init ; Hotkeys for script control. #g::Suspend +#g::Reload ^#g::Edit !#g::ExitApp ;------------------------------------------------------------------------------ action_init: ; Define some API constants. WM_VSCROLL = 0x115 SB_LINEUP = 0 SB_LINEDOWN = 1 SB_PAGEUP = 2 SB_PAGEDOWN = 3 SB_TOP = 6 SB_BOTTOM = 7 WM_HSCROLL = 0x114 SB_LINELEFT = 0 SB_LINERIGHT = 1 SB_PAGELEFT = 2 SB_PAGERIGHT = 3 SB_LEFT = 6 SB_RIGHT = 7 ; Indicate how each action should scroll. LBmsg = %WM_VSCROLL% ; Left button - Scroll down by one page. LBarg = %SB_PAGEDOWN% MBmsg = %WM_VSCROLL% ; Middle button - Scroll up by one page. MBarg = %SB_PAGEUP% WUmsg = %WM_HSCROLL% ; Wheel up - Scroll left by one page. WUarg = %SB_PAGELEFT% WDmsg = %WM_HSCROLL% ; Wheel down - Scroll right by one page. WDarg = %SB_PAGERIGHT% Lmsg = %WM_HSCROLL% ; Left - Scroll to the beginning. Larg = %SB_LEFT% Rmsg = %WM_HSCROLL% ; Right - Scroll to the end. Rarg = %SB_RIGHT% Umsg = %WM_VSCROLL% ; Up - Scroll to the top. Uarg = %SB_TOP% Dmsg = %WM_VSCROLL% ; Down - Scroll to the bottom. Darg = %SB_BOTTOM% return ; ----------------------------------------------------------------------------- ; Scroll the window under the cursor in various ways. LB_Action: MB_Action: WU_Action: WD_Action: L_Action: R_Action: U_Action: D_Action: Transform msg, Deref, `%%mg_str%msg`% Transform arg, Deref, `%%mg_str%arg`% MouseGetPos,,, id, control PostMessage %msg%, %arg%, 0, %control%, ahk_id %id% return ; ----------------------------------------------------------------------------- LR_Action: ; Close the active window. WinClose A return ; ----------------------------------------------------------------------------- desktop_and_active: WinGetPos,,, dw, dh, Program Manager WinGet t,, A WinGetPos x, y, w, h, ahk_id %t% return ; Change the size of the active window. ; The first time will change, the second will restore. RL_Action: ; Maximise the width. gosub desktop_and_active if t = %old_t% if x = 0 if w = %dw% { WinMove A,, %old_x%,, %old_w% return } WinMove A,, 0,, %dw% old_t = %t% old_x = %x% old_w = %w% return DU_Action: ; Maximise the height. gosub desktop_and_active if t = %old_t% if y = 0 if h = %dh% { WinMove A,,, %old_y%,, %old_h% return } WinMove A,,, 0,, %dh% old_t = %t% old_y = %y% old_h = %h% return ; ----------------------------------------------------------------------------- ; Change the position of the active window. ; The first time will change, the second will restore. position: if t = %p_t% if x = %new_x% if y = %new_y% { WinMove A,, %p_x%, %p_y% p_t = return } WinMove A,, %new_x%, %new_y% if p_t <> %t% { p_t = %t% p_x = %x% p_y = %y% } return LD_Action: UR_Action: ; Position the window in the top-left corner. gosub desktop_and_active new_x = 0 new_y = 0 goto position RD_Action: UL_Action: ; Position the window in the top-right corner. gosub desktop_and_active new_x = %dw% new_x -= %w% new_y = 0 goto position RU_Action: DL_Action: ; Position the window in the bottom-right corner. gosub desktop_and_active new_x = %dw% new_x -= %w% new_y = %dh% new_y -= %h% goto position LU_Action: DR_Action: ; Position the window in the bottom-left corner. gosub desktop_and_active new_x = 0 new_y = %dh% new_y -= %h% goto position UD_Action: ; Center the window. gosub desktop_and_active new_x = %dw% new_x -= %w% new_x /= 2 new_y = %dh% new_y -= %h% new_y /= 2 goto position ;------------------------------------------------------------------------------ MButton:: mb = M goto MouseButton LButton:: mb = L MouseButton: if mg_active = 1 { ifEqual mg_show,, Tooltip mg_executed = 1 mg_str = %mb%B goto %mg_str%_Action } ; I like to use middle button as left double-click. if mb = M { MouseClick L,,, 2 return } ButtonWait: MouseClick %mb%,,,,,D loop { GetKeyState st, %mb%Button, P ifEqual st, U, break Sleep 10 } MouseClick %mb%,,,,,U return WheelUp:: mg_str = WU goto Wheel WheelDown:: mg_str = WD Wheel: if mg_active = 1 { ifEqual mg_show,, Tooltip mg_executed = 1 goto %mg_str%_Action } MouseClick %mg_str% return RButton:: MouseGetPos,,, id WinGetTitle mg_title, ahk_id %id% if mg_title contains %disabled% Suspend else if mg_title not contains %excluded% { mg_active = 1 mg_executed = 0 mg_rheld = 0 mg_str = mg_idletime = 0 ifEqual mg_show,, ToolTip %A_Space% MouseGetPos px, py px2 = %px% py2 = %py% loop { GetKeyState st, RButton, P if st = U { ifEqual mg_show,, ToolTip if mg_rheld = 0 { mg_active = 0 if mg_executed = 0 if mg_str = MouseClick R else ifInString gestures, -%mg_str%- gosub %mg_str%_Action else ifEqual mg_rclick,, MouseClick R } else MouseClick R,,,,,U return } else if mg_idletime < %timeout% { MouseGetPos dx, dy dx -= %px2% dy -= %py2% if dx > %sensitivity% mg_dir = R else if dx < -%sensitivity% mg_dir = L else if dy > %sensitivity% mg_dir = D else if dy < -%sensitivity% mg_dir = U if mg_dir <> { mg_str = %mg_str%%mg_dir% ifEqual mg_show,, ToolTip %mg_str% MouseGetPos px2, py2 mg_idletime = 0 mg_dir = } else mg_idletime++ } else if mg_rheld = 0 if mg_executed = 0 { MouseGetPos px2, py2 if px2 <> %px% if py2 <> %py% { ifEqual mg_show,, ToolTip MouseClick R, %px%, %py%,,,D MouseMove %px2%, %py2% mg_rheld = 1 mg_active = 0 } } Sleep 10 } } mb = R goto ButtonWait