i have changed the way wheelup and down are used. rather than track wheelup and wheeldown, the script now uses the wheel in a more natural way. for example (see glw example) you can gesture left and if you keep the right button depressed, use the wheel to adjust volume (for example) up and down.
also, i found that using the left mouse click worked more efficiently if it terminated the gesture. for example, if you hold the right button, then click on the left button, the action gc: is run immediately (rather than waiting for the right button to be released)
Code:
;Simple Mouse Gestures call subroutines based on a gesture made when the right button is held down.
;the script tracks up (u) down (d) left (l) right (r). There is a tolerance of +/- 45 degrees, so it is quite simple and accurate
;by not allowing diagonals, gestures can have curves. eg a circle drawn from the top and clockwise is registered as rdlu (right down left up)
;if a gesture is down (d) and right (r), like an "L", a subroutine called gdr ( for gesture down right) will be called
;if anything is labelled as gdr:, the action will be run
;as a further example, if an "S" is drawn (from top to bottom), gldrdl: (gesture left down right down left) will be called
;these 2 examples are included. See below for further examples
;in addition, gestures can be terminated by a left click (c), which modifies the subroutine called. eg gudc (gesture up down click)
;also, the action of wheelup and wheeldown (w) can be modified depending on gesture. eg if you gesture left, and keep the right button depressed, you can use the wheel (up or down) for any use you define. see glw: example which adjusts volume
CoordMode, Mouse, Screen
winget, window0, id, ahk_class Progman ;window0 is the desktop
hotkey, lbutton, off ;allows normal left click function
rbutton::
hotkey, lbutton, on ;disables normal left click
if (window1<>window0)
window2:=window1 ;window1 is the window underneath the current gesture, window2 is from the previous gesture
mousegetpos,xpos1, ypos1,window1
gesture= ;clear previous tracking results
settimer, gesture, 10
GestureMode = 1
return
rbutton up::
if not gesturemode
return
settimer, gesture, off
hotkey, lbutton, off ;re-enables normal left click
GestureMode = 0
gesture := "g" . gesture ;eg. gdr = gesture down right
if islabel(gesture) ;checks if gesture is labelled
gosub, %gesture% ; eg. gosub, gdr
return
gesture:
if SubStr(gesture, 0)="w" ;if using wheel, this stops mouse drift stopping gesture
return
mousegetpos,xpos2, ypos2
dx:=xpos2-xpos1
dy:=ypos1-ypos2
if (abs(dy)>=abs(dx))
{
if (dy>0)
track=u ;track is up
else
track=d ;down
}
else
{
if (dx>0)
track=r ;right
else
track=l ;left
}
if (abs(dy)<4 and abs(dx)<4)
track= ;not tracking at all if no significant change in x or y
xpos1:=xpos2
ypos1:=ypos2
if (track<>SubStr(gesture, 0, 1)) ;ignore track if not changing since previous track
gesture := gesture . track
return
lbutton:: ;registers a left click. terminates the gesture
gesture := gesture . "c"
gosub, rbutton up ;delete this line if you don't want left clicks to terminate the gesture
gesturemode=0 ;delete this line if you don't want left clicks to terminate the gesture
return
WheelUp::
If GestureMode ;we're currently recording a gesture
{
If (SubStr(gesture, 0) <> "w")
gesture := "g" . gesture . "w"
wheelup=1
if islabel(gesture)
gosub, %gesture%
}
Else ;we're not recording a gesture so just do a wheelup
Sendinput {WheelUp}
Return
WheelDown:: ;ditto for down
If GestureMode
{
If (SubStr(gesture, 0) <> "w")
gesture := "g" . gesture . "w"
wheelup=0
if islabel(gesture)
gosub, %gesture%
}
Else
Sendinput {WheelDown}
Return
g: ;normal right click
click, right, xpos1, ypos1
exit
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;; Examples ;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;; wheel examples ;;;;;;;;;;
glw: ;change volume with wheel
if wheelup
Send {Volume_Up}
else
Send {Volume_Down}
return ;end wheel gestures with a "return" NOT "exit" !!!!!!!!
;;;;;;;; click examples ;;;;;;;;;;
gc:
msgbox,,,rocker,5
exit ;end all labels (other than wheel gestures) with "exit" NOT "return"
glc:
msgbox,,,you gestured left and clicked,5
exit
;;;;;;;; other examples ;;;;;;;;;;;;;;
gu: ;; gesture up ;; maximize window under cursor. maximize last window if cursor over desktop
if (window1=window0)
{
if (window2<>"")
winmaximize, ahk_id %window2%
}
else
winmaximize, ahk_id %window1%
exit
gd: ;minimize window under cursor
if (window1<>window0) ;don't minimize the desktop
winminimize, ahk_id %window1%
exit
gl: ;browser back
winactivate, ahk_id %window1%
sendinput, {Browser_Back}
exit
gr: ;browser forward
winactivate, ahk_id %window1%
sendinput, {Browser_Forward}
exit
gdr: ;restore last window.
winrestore, ahk_id %window2%
exit
gldr: ;close window under cursor (draw a C)
if (window1<>window0)
winclose, ahk_id %window1%
exit
gldrdl:
msgbox, you drew an S
exit
gurdurd:
msgbox, you drew an M
exit