AutoHotkey Homepage AutoHotkey Community
Let's help each other out
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Simple Mouse Gesture and Rocker
Goto page Previous  1, 2, 3, 4, 5, 6, 7, 8  Next
 
Reply to topic    AutoHotkey Community Forum Index -> Scripts & Functions
View previous topic :: View next topic  
Author Message
rodfell



Joined: 05 Oct 2007
Posts: 138
Location: Bundaberg (Bundy), Qld, Australia

PostPosted: Fri Jun 05, 2009 9:09 pm    Post subject: Reply with quote

the program takes over the middle mouse key. any action that other programs use the middle key for has to be reproduced in the m-m: macro
Back to top
View user's profile Send private message
rodfell



Joined: 05 Oct 2007
Posts: 138
Location: Bundaberg (Bundy), Qld, Australia

PostPosted: Fri Jun 19, 2009 11:13 pm    Post subject: accuracy Reply with quote

i find with sloppy gesturing, sometimes when the transition is made from say down to right, a 45 degree error is made. what's a 45 degree error? if a long gesture is made at roughly 45 degrees (say down and right) then the gesture will come back as m-r(drdrdrdrdr.. etc) which is plainly a bug. so if for example an "L" is drawn down and then right (m-r(dr): ), if one is sloppy the following erroneous gesture might be registered - m-r(drdr): . the whole point of not allowing diagonals is to allow for sloppy yet accurate gestures. for the moment, i've fixed the bug by ignoring angles 10 degrees either side of 45 (35 to 55 degrees or dx/dy between 0.7 and 1.428)
Code:
multiclicktime=300    ; set to 0 if you don't want double/triple/multi clicking. otherwise set as fast as you can double-click
sensitivity=4      ; adjust if required. if too low, a simple "down/up" gesture (V) might be recorded as "down/right/up" (U)
demomode:=true      ; demonstration mode on/off

coordmode,mouse,screen
winget,windowD,id,ahk_class Progman   ;windowD is the desktop, useful for some gestures
gosub cleanup
#maxthreadsbuffer on
browser_search::          ; "find" key on logitech mx620 mouse, used here as an example
lbutton::     
rbutton::      ; list whatever mouse buttons you want tracked.
mbutton::      ; works best if all available listed
xbutton1::         ; lbutton only tracked when other mouse buttons start tracking
xbutton2::
thishotkey:=a_thishotkey="xbutton2" ? "f" : substr(a_thishotkey,1,1)   ;buttons named from initial except xbutton2
gosub multiclick
winget,windowA,id,A     ; windowA is the active window, useful for some gestures
hotkey,lbutton,on         ; disables normal left click during gesture
hotkey,lbutton up,off   ; prevents next line of code from firing "lbutton up:"
click up      ; prevents drag box appearing when left/right rocking and gesturing eg. m-l/r(d)
hotkey,lbutton up,on
if (window1<>windowD)     
   window2:=window1         ; used in some gestures, window2 is the window the previous macro acted on           
mousegetpos xpos1,ypos1,window1   ; window1 is the window underneath the current gesture
if gtracking
   {
   gosub trackassign
   record.=(getkeystate("lbutton","p") and not record ? "l/" : "") . (record and thishotkey<>substr(record,0,1) ? "/" : "") . thishotkey
   settimer,gtrack,10         
   }                         
else
   {
   gosub parserecord   ; finds position of last "/" in record for next line of code
   record:=regexreplace(record,"/\w*","/" . thishotkey . multitrack,position,1,position)
   }     
if instr(record,thishotkey . "/")
   gosub cleanup      ; cleanup if unlikely but fatal error detected
return

browser_search up::     
rbutton up::
lbutton up::
mbutton up::
xbutton1 up::
xbutton2 up::
buttonsup.=a_thishotkey="xbutton2" ? "f" : substr(a_thishotkey,1,1)
multiclick:=false
if not gtrack   ; no need for delay to check for multiclick if button released after gesture tracking
   sleep % multiclicktime-a_tickcount+time1  ;delay to check for multiclick
if multiclick or not buttonsup
   return
thishotkey:=substr(buttonsup,1,1)
stringreplace,buttonsup,buttonsup,%thishotkey%,,all
gtracking:=false  ; no more gesture tracking once a mouse button has been released (unless multiclicking)
gosub trackassign
cleanup:=(rock()<>"rocking") or wheel ? true : false   ; this allows for repeat rocking   
callmacro:=not wheel and record and not (rock()="over" and mcalled) ? true : false
if cleanup         ; these lines allow for cleanup before the macro action is called.
   gosub cleanup      ; (note that the gesture itself is not erased by the cleanup). this prevents a called
if callmacro         ;  action that takes a significant time stopping further tracking.
   gosub callmacro   
return           
#maxthreadsbuffer off
     
callmacro:
mcalled:=true
macro.=(wheel ? "-" : "") . wheel
if demomode
   msgbox,,Demo,%macro%, % (wheel ? .7 : strlen(gesture)/4+1)
else
   if islabel(macro)   ; checks if macro is labelled
         gosub %macro%
return

cleanup:
hotkey,lbutton,off             ; restore normal left mouse button function
hotkey,lbutton up,off
settimer,gtrack,off
record:="",wheel="",gtrack="",mcalled="",gtracking=true
return

gtrack:
critical off      ; don't want this getting in way of double-click checking
mousegetpos xpos2,ypos2
angle:=abs(xpos1-xpos2)/abs(ypos1-ypos2)
if angle between 0.7 and 1.428   ; ignores angles 10 degrees either side of 45 degrees
   return
track:=(abs(ypos1-ypos2)>=abs(xpos1-xpos2)) ? (ypos1>ypos2 ? "u" : "d") : (xpos1>xpos2 ? "l" : "r")  ;determines up down left right
if (abs(ypos1-ypos2)>sensitivity or abs(xpos1-xpos2)>sensitivity) and (track<>SubStr(gtrack, 0, 1)) ;track if x or y changing and direction changing
   gtrack.=track
xpos1:=xpos2,ypos1:=ypos2
return

parserecord:      ; script allows for rocking more than once eg m-r/l/x:
loop,parse,record        ; finds position of last "/"
   if a_loopfield=/
      position:=a_index
return

multiclick:
time2:=time1,time1:=a_tickcount     
if (thishotkey=substr(record,0,1) and time1-time2<multiclicktime)
    multiclick:=true,multitrack.=thishotkey
else
   multiclick:=false,multitrack:=""
return

trackassign:
settimer,gtrack,off
if gtrack               ; letters enclosed in parentheses
   record.="(" . gtrack . ")"         ;  are gesture directions
gtrack=               
macro:="m-" . record
return

esc::
exitapp
return

wheelup::
wheeldown::
if record and gtracking   
      {
   wheel:=a_thishotkey
   gosub trackassign   
      gosub callmacro
   }
else
      sendinput {%a_thishotkey%}
return

rock()
{
global
if record contains /      ; "/" is the rocking symbol
   {
   gosub parserecord   
   return (thishotkey=substr(record,position+1,1)) ? "rocking" : "over"
   }         ; "position+1" is the first letter after the forward slash
}

m-r:          ;normal right click
click right
return

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

;;;;;;; Examples ;;;;;;;;;;;;;;;;;;;;;;;;;;

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

;;;;; wheel examples ;;;;;;;;;;

m-r-wheelup:      ;change volume with wheel -  hold right button down and use wheel
Send {Volume_Up}
return

m-r-wheeldown:
Send {Volume_Down}
return

;;;;;;;; multi click examples ;;;;;;;;;;

m-rr:
msgbox,,,double right click,5
return

m-rr(l):
msgbox,,,double right click then gesture left ,5
return

m-rr/ll:
msgbox,,,double right click then rock with double right ,5
return

m-r/l/m:
msgbox,,,right click then rock with left and then middle ,5
return

;;;;;;;; rocker examples ;;;;;;;;;;

m-r/l:
msgbox,,,keep right held down and click left will repeat action,5
return

m-l/r:                                           
msgbox,,,rocker left then right. careful where you click,5
return

m-r(l)/l:
msgbox,,,you gestured left and clicked,5
return

;;;;;;;;;;;; 4th mouse button example ;;;;;;;;;;

m-x(l):
msgbox,,,you've gestures left with the 4th mouse button,5
return

m-x/r:
msgbox,,,rocker 4th button then right,5
return

m-r/x:
msgbox,,,rocker right then 4th button,5
return

;;;;;;;; other examples ;;;;;;;;;;;;;;

m-r(u):             ;; gesture up ;; maximize window under cursor. maximize last window if cursor over desktop
if (window1=windowD)
   {
   if (window2<>"")
   winmaximize, ahk_id %window2%
   }
else
   winmaximize ahk_id %window1%
return

m-rd:            ;minimize window under cursor
if (window1<>windowD)    ;don't minimize the desktop
   winminimize, ahk_id %window1%
return

m-r(l):            ;browser back
winactivate ahk_id %window1%   
sendinput {Browser_Back}
return

m-r(r):            ;browser forward
winactivate ahk_id %window1%   
sendinput {Browser_Forward}
return

m-r(dr):            ;restore last window.
winrestore ahk_id %window2%
return

m-r(ldr):            ;close window under cursor (draw a C)
if (window1<>windowD)
   winclose ahk_id %window1%
return

Back to top
View user's profile Send private message
Guest






PostPosted: Sat Oct 17, 2009 5:56 pm    Post subject: Is there any option to track move movement without rclick ? Reply with quote

Is there any option to track move movement without rclick or any other "gestures" button ?
Back to top
rodfell



Joined: 05 Oct 2007
Posts: 138
Location: Bundaberg (Bundy), Qld, Australia

PostPosted: Mon Jun 14, 2010 2:57 am    Post subject: back to simple Reply with quote

I have found that multiclicking makes gesturing less accurate, so I have removed it. I've also found that when combining gestures and rocking, it shouldn't matter what order is used eg right click-gesture-left click is more accurate and simple if right click-left click-gesture gives the same result.
Code:
sensitivity=4      ; adjust if required. if too low, a simple "down/up" gesture (V) might be recorded as "down/right/up" (U)
demomode:=true     ; demonstration mode on/off
coordmode,mouse,screen
winget,windowD,id,ahk_class Progman   ;windowD is the desktop, useful for some gestures
gosub cleanup

lbutton::     
rbutton::     
mbutton::     
xbutton1::         
xbutton2::
if macrorunning
   return
downclick:=a_thishotkey="xbutton2" ? "f" : substr(a_thishotkey,1,1)
buttonsdown.=(getkeystate("lbutton","p") and not buttonsdown ? "l" : "") . downclick
mouseclick:=buttonsdown     ;record of buttons clicked
winget,windowA,id,A     ; windowA is the active window, useful for some gestures
if (window1<>windowD)     
   window2:=window1     ; used in some gestures, window2 is the window the previous macro acted on
hotkey,lbutton up,off   ; prevents next line of code from firing "lbutton up:"
click up            ; prevents drag box appearing when left/right rocking and gesturing eg. m-lr/d
hotkey,lbutton,on       ; lbutton only tracked when other mouse buttons start tracking
hotkey,lbutton up,on
mousegetpos xpos1,ypos1,window1   ; window1 is the window underneath the current gesture
if gtracking
   settimer,gtrack,10         
return

rbutton up::
lbutton up::
mbutton up::
xbutton1 up::
xbutton2 up::
upclick:=a_thishotkey="xbutton2 up" ? "f" : substr(a_thishotkey,1,1)
stringreplace,buttonsdown,buttonsdown,%upclick%,,all
gtracking:=false  ; no more gesture tracking once a mouse button has been released
gosub namemacro
callmacro:=(not wheel and substr(mouseclick,0,1)=upclick) ? true : false
if not buttonsdown         
   gosub cleanup     
if callmacro         
   goto callmacro   ;for efficiency, cleanup occurs before the macro is called
return

namemacro:
settimer,gtrack,off
macro:="m-" . mouseclick . (if gtrack ? "(" : "") . gtrack . (if gtrack ? ")" : "")
return         
     
callmacro:
macrorunning:=true
macro.=(wheel ? "-" : "") . wheel
if demomode
   msgbox,,Demo,%macro%, % (wheel ? .7 : strlen(gesture)/4+1.5)   
else
   if islabel(macro)   ; checks if macro is labelled
         gosub %macro%
macrorunning:=false
return

gtrack:
mousegetpos xpos2,ypos2
angle:=abs((xpos1-xpos2)/(ypos1-ypos2))
if angle between 0.7 and 1.428   ; ignores angles within 10 degrees of 45 degree diagonal
   return
track:=(abs(ypos1-ypos2)>=abs(xpos1-xpos2)) ? (ypos1>ypos2 ? "u" : "d") : (xpos1>xpos2 ? "l" : "r")  ;determines up down left right
if (abs(ypos1-ypos2)>sensitivity or abs(xpos1-xpos2)>sensitivity) and (track<>SubStr(gtrack, 0, 1)) ;track if x or y changing and direction changing
   gtrack.=track
xpos1:=xpos2,ypos1:=ypos2
return

cleanup:
hotkey,lbutton,off             ; restore normal left mouse button function
hotkey,lbutton up,off
settimer,gtrack,off
wheel:="",gtrack="",gtracking=1,mouseclick="",buttonsdown=""
return

wheelup::
wheeldown::
if buttonsdown and gtracking   
   {
   wheel:=a_thishotkey
   gosub namemacro   
   gosub callmacro
   }
else
   sendinput {%a_thishotkey%}
return

esc::
exitapp
return

m-r:          ;normal right click
click right
return

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

;;;;;;; Examples ;;;;;;;;;;;;;;;;;;;;;;;;;;

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

;;;;; wheel examples ;;;;;;;;;;

m-r-wheelup:      ;change volume with wheel -  hold right button down and use wheel
Send {Volume_Up}
return

m-r-wheeldown:
Send {Volume_Down}
return

;;;;;;;; rocker examples ;;;;;;;;;;

m-rl:
msgbox,,,if you keep right held down, clicking left will repeat action,5
return

m-lr:                                           
msgbox,,,rocker left then right. careful where you click,5
return

m-rl(l):
m-lr(l):
msgbox,,,you combined rocking and gesturing,5
return

;;;;;;;;;;;; gesture examples ;;;;;;;;;;

m-r(u):             ;; gesture up ;; maximize window under cursor. maximize last window if cursor over desktop
if (window1=windowD)
   {
   if (window2<>"")
   winmaximize, ahk_id %window2%
   }
else
   winmaximize ahk_id %window1%
return

m-r(d):            ;minimize window under cursor
if (window1<>windowD)    ;don't minimize the desktop
   winminimize, ahk_id %window1%
return

m-r(l):            ;browser back
winactivate ahk_id %window1%   
sendinput {Browser_Back}
return

m-r(r):            ;browser forward
winactivate ahk_id %window1%   
sendinput {Browser_Forward}
return

m-r(dr):            ;restore last window.
winrestore ahk_id %window2%
return

m-r(ldr):            ;close window under cursor (draw a C)
if (window1<>windowD)
   winclose ahk_id %window1%
return
Back to top
View user's profile Send private message
rodfell



Joined: 05 Oct 2007
Posts: 138
Location: Bundaberg (Bundy), Qld, Australia

PostPosted: Thu Jun 17, 2010 5:34 am    Post subject: middle button/wheel errors Reply with quote

small change to prevent middle button/wheel errors. if gesturing with middle button, wheel movement ignored. If using wheel, middle clicks ignored.
Code:
sensitivity=4      ; adjust if required. if too low, a simple "down/up" gesture (V) might be recorded as "down/right/up" (U)
demomode:=true     ; demonstration mode on/off. change to false when ready to use

winget,windowD,id,ahk_class Progman   ;windowD is the desktop, useful for some gestures
gosub cleanup

mbutton::
lbutton::     
rbutton::     
xbutton1::         
xbutton2::
if macrorunning or wheel
   return
buttonsdown.=not buttonsdown and getkeystate("lbutton") ? "l" : ""
buttonsdown.=a_thishotkey="xbutton2" ? "f" : substr(a_thishotkey,1,1)
mouseclick:=buttonsdown     ;record of buttons clicked
winget,windowA,id,A     ; windowA is the active window, useful for some gestures
hotkey,lbutton up,off   ; prevents next line of code from firing "lbutton up:"
click up            ; prevents drag box appearing when left/right rocking and gesturing eg. m-lr(d):
hotkey,lbutton,on       ; lbutton only tracked when other mouse buttons start tracking
hotkey,lbutton up,on
mousegetpos xpos1,ypos1,window1   ; window1 is the window underneath the current gesture
if not buttonsup
   settimer,gtrack,10         
return

mbutton up::
if wheel     
   return
rbutton up::
lbutton up::
xbutton1 up::
xbutton2 up::
lastup:=a_thishotkey="xbutton2 up" ? "f" : substr(a_thishotkey,1,1)
stringreplace,buttonsdown,buttonsdown,%lastup%,,all
buttonsup:=true
settimer,gtrack,off    ; no more gesture tracking once a mouse button has been released
if not wheel and substr(mouseclick,0,1)=lastup
   gosub callmacro   
if not buttonsdown         
   gosub cleanup
return
     
callmacro:
macrorunning:=true
macro:="m-" . mouseclick . (if gtrack ? "(" : "") . gtrack . (if gtrack ? ")" : "") . (wheel ? "-" : "") . wheel
if demomode
   msgbox,,DEMO MODE, %macro%, 1   
else
   if islabel(macro)   ; checks if macro is labelled
         gosub %macro%
macrorunning:=false
return

gtrack:
mousegetpos xpos2,ypos2
angle:=abs((xpos1-xpos2)/(ypos1-ypos2))
if angle between 0.7 and 1.428   ; ignores angles within 10 degrees of 45 degree diagonal
   return
track:=(abs(ypos1-ypos2)>=abs(xpos1-xpos2)) ? (ypos1>ypos2 ? "u" : "d") : (xpos1>xpos2 ? "l" : "r")  ;determines up down left right
if (abs(ypos1-ypos2)>sensitivity or abs(xpos1-xpos2)>sensitivity) and (track<>SubStr(gtrack, 0, 1)) ;track if x or y changing sufficient to register
   gtrack.=track
xpos1:=xpos2,ypos1:=ypos2
return

cleanup:
if (window1<>windowD)     
   window2:=window1     ; used in some gestures, window2 is the window the previous macro acted on
hotkey,lbutton,off             ; restore normal left mouse button function
hotkey,lbutton up,off
wheel:="",gtrack="",buttonsup="",mouseclick="",buttonsdown=""
return

wheelup::
wheeldown::
ifinstring,buttonsdown,m    ;prevents accidental use of mousewheel with middle button gestures   
   return       
if buttonsdown and not buttonsup
   {   
   wheel:=a_thishotkey
   settimer,gtrack,off   ;no more tracking once wheel used
   gosub callmacro
   }
if not buttonsdown
   sendinput {%a_thishotkey%}
return

esc::exitapp

m-r:          ;normal right click
click right
return

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

;;;;;;; Examples ;;;;;;;;;;;;;;;;;;;;;;;;;;

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

;;;;; wheel examples ;;;;;;;;;;

m-r-wheelup:      ;change volume with wheel -  hold right button down and use wheel
Send {Volume_Up}
return

m-r-wheeldown:
Send {Volume_Down}
return

;;;;;;;; rocker examples ;;;;;;;;;;

m-rl:
msgbox,,,if you keep right held down, clicking left will repeat action,5
return

m-lr:                                           
msgbox,,,rocker left then right. careful where you click,5
return

m-rl(l):
m-lr(l):
msgbox,,,you combined rocking and gesturing,5
return

;;;;;;;;;;;; gesture examples ;;;;;;;;;;

m-r(u):             ;; gesture up ;; maximize window under cursor. maximize last window if cursor over desktop
if (window1=windowD)
   {
   if (window2<>"")
   winmaximize, ahk_id %window2%
   }
else
   winmaximize ahk_id %window1%
return

m-r(d):            ;minimize window under cursor
if (window1<>windowD)    ;don't minimize the desktop
   winminimize, ahk_id %window1%
return

m-r(l):            ;browser back
winactivate ahk_id %window1%   
sendinput {Browser_Back}
return

m-r(r):            ;browser forward
winactivate ahk_id %window1%   
sendinput {Browser_Forward}
return

m-r(dr):            ;restore last window.
winrestore ahk_id %window2%
return

m-r(ldr):            ;close window under cursor (draw a C)
if (window1<>windowD)
   winclose ahk_id %window1%
return
 
Back to top
View user's profile Send private message
rodfell



Joined: 05 Oct 2007
Posts: 138
Location: Bundaberg (Bundy), Qld, Australia

PostPosted: Thu Jun 24, 2010 5:28 am    Post subject: diagonal gestures Reply with quote

been playing around with diagonal gestures. i think error rate too high with sloppy careless gesturing (which is how I and I suspect others gesture). In any event I have included the code I came up with. Diagonal taken as 15 degrees either side of 45 degrees.
Code:
demomode:=true     ; demonstration mode on/off. change to false when ready to use

winget,windesktop,id,ahk_class Progman   ;desktop id, useful for some gestures
gosub cleanup

mbutton::
lbutton::     
rbutton::     
xbutton1::         
xbutton2::
if macrorunning or wheel
   return
buttonsdown.=(not buttonsdown and getkeystate("lbutton") ? "l" : "") . (a_thishotkey="xbutton2" ? "f" : substr(a_thishotkey,1,1))
mouseclick:=buttonsdown     ;record of buttons clicked
winget,winactive,id,A       ;active window id, useful for some gestures
click up                    ;prevents drag box appearing when left/right rocking and gesturing eg. m-lr(d):
hotkey,lbutton,on           ;lbutton only tracked when other mouse buttons start tracking
hotkey,lbutton up,on
mousegetpos xpos1,ypos1,win1      ;win1 is the window underneath the current gesture
if not buttonsup
   settimer,gtrack,10         
return

mbutton up::
if wheel     
   return
rbutton up::
lbutton up::
xbutton1 up::
xbutton2 up::
lastup:=a_thishotkey="xbutton2 up" ? "f" : substr(a_thishotkey,1,1)
stringreplace,buttonsdown,buttonsdown,%lastup%,,all
buttonsup:=true
settimer,gtrack,off    ;no more gesture tracking once a mouse button has been released
if not wheel and substr(mouseclick,0,1)=lastup
   gosub callmacro   
if not buttonsdown         
   gosub cleanup
return
     
callmacro:
macrorunning:=true
macro:="m-" . mouseclick . (gtrack ? "(" . gtrack . ")" : "") . (wheel ? "-" . wheel : "")
if demomode
   msgbox,,DEMO MODE, %macro%, 1   
else
   if islabel(macro)       ;checks if macro is labelled
         gosub %macro%
macrorunning:=false
return

gtrack:
mousegetpos xpos2,ypos2
angle:=abs((xpos1-xpos2)/(ypos1-ypos2+0.01))
if (angle>0.268 and angle<0.577) or (angle>1.732 and angle<3.732) or (abs(ypos1-ypos2)<=5 and abs(xpos1-xpos2)<=5) 
   return
if angle between 0.577 and 1.732
   track1:=(ypos1>ypos2) ? (xpos2>xpos1 ? "9" : "7") : (xpos2>xpos1 ? "3" : "1")
else
   track1:=(abs(ypos1-ypos2)>=abs(xpos1-xpos2)) ? (ypos1>ypos2 ? "u" : "d") : (xpos1>xpos2 ? "l" : "r")  ;determines up down left right
count:=(track1<>track2) ? "1" : count+1
if count=3
   gtrack.=track1
xpos1:=xpos2,ypos1:=ypos2,track2:=track1
return

cleanup:
if (win1<>windesktop)     
   win2:=win1     ; used in some gestures, win2 is the window the previous macro acted on
hotkey,lbutton,off             ; restore normal left mouse button function
hotkey,lbutton up,off
wheel:="",gtrack="",buttonsup="",mouseclick="",buttonsdown=""
return

wheelup::
wheeldown::
if instr(buttonsdown,"m") or macrorunning    ;prevents accidental use of mousewheel with middle button gestures   
   return   
if buttonsdown and not buttonsup
   {   
   wheel:=a_thishotkey
   settimer,gtrack,off   ;no more tracking once wheel used
   gosub callmacro
   }
if not buttonsdown
   sendinput {%a_thishotkey%}
return

esc::exitapp

m-r:                     ;normal right click
click right
return

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

;;;;;;; Examples ;;;;;;;;;;;;;;;;;;;;;;;;;;

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

;;;;; wheel examples ;;;;;;;;;;

m-r-wheelup:      ;change volume with wheel -  hold right button down and use wheel
Send {Volume_Up}
return

m-r-wheeldown:
Send {Volume_Down}
return

;;;;;;;; rocker examples ;;;;;;;;;;

m-rl:
msgbox,,,if you keep right held down, clicking left will repeat action,5
return

m-lr:                                           
msgbox,,,rocker left then right. careful where you click,5
return

m-rl(l):
m-lr(l):
msgbox,,,you combined rocking and gesturing,5
return

;;;;;;;;;;;; gesture examples ;;;;;;;;;;

m-r(u):             ;; gesture up ;; maximize window under cursor. maximize last window if cursor over desktop
if (win1=windesktop)
   {
   if (win2<>"")
   winmaximize, ahk_id %win2%
   }
else
   winmaximize ahk_id %win1%
return

m-r(d):            ;minimize window under cursor
if (win1<>windesktop)    ;don't minimize the desktop
   winminimize, ahk_id %win1%
return

m-r(l):            ;browser back
winactivate ahk_id %win1%   
sendinput {Browser_Back}
return

m-r(r):            ;browser forward
winactivate ahk_id %win1%   
sendinput {Browser_Forward}
return

m-r(dr):            ;restore last window.
winrestore ahk_id %win2%
return

m-r(ldr):            ;close window under cursor (draw a C)
if (win1<>windesktop)
   winclose ahk_id %win1%
return
Back to top
View user's profile Send private message
ratchetclan4



Joined: 14 Apr 2010
Posts: 18

PostPosted: Thu Jun 24, 2010 9:24 pm    Post subject: Reply with quote

This is so awesome ^.^

i like using it for webpages like drawing a Y

gdud:
msgbox, 4,, Youtube?
ifmsgbox yes
run iexplore.exe "www.youtube.com"
else
exit
Back to top
View user's profile Send private message
rodfell



Joined: 05 Oct 2007
Posts: 138
Location: Bundaberg (Bundy), Qld, Australia

PostPosted: Fri Jun 25, 2010 12:03 am    Post subject: Reply with quote

thx ratchetclan4. always appreciate feedback. glad you get that you don't need diagonals to draw a "y". gesture down up down is much quicker and easier; yet still easy to remember as you still draw it as a "y"
btw, gdud: now m-r(dud):

As always, the most up to date code on page 1 Smile
Back to top
View user's profile Send private message
rodfell



Joined: 05 Oct 2007
Posts: 138
Location: Bundaberg (Bundy), Qld, Australia

PostPosted: Fri Jun 25, 2010 11:37 am    Post subject: Reply with quote

changed a few things to further increase accuracy. Any track needs confirmation ie there needs to be at least 2 tracks in the same direction. A gesture stroke needs to be a certain length (in pixels) before it is registered.These changes were primarily designed to avoid a gesture like a "V" ( m-r(du): ) being accidentally registered as a "U" ( m-r(dru): ). A benefit of the changes is that gestures can now be drawn very slowly (improving windows accessibility).
Code:
/*
 *      User defined variables
 */

demomode:=true     ;demonstration mode on/off. change to false when ready to use
autoreturn:=true   ;returns cursor to where gesture began (especially useful with trackballs)
mintrack=20      ;minimum length of registered track sector in pixels   

/*
 *   
 */

winget,windesktop,id,ahk_class Progman   ;desktop id, useful for some gestures
gosub cleanup
if demomode
   msgbox,,DEMO MODE,Please note that you are in demonstration mode. `n`nA message box will tell you what gesture or rocking action you make,6

mbutton::
lbutton::     
rbutton::     
xbutton1::         
xbutton2::
if macrorunning or wheel
   return
if not buttonsdown             ;win1 is the window underneath the current gesture
   mousegetpos xpos,ypos,win1 
buttonsdown.=(not buttonsdown and getkeystate("lbutton") ? "l" : "") . (a_thishotkey="xbutton2" ? "f" : substr(a_thishotkey,1,1))
mouseclick:=buttonsdown        ;record of buttons clicked
winget,winactive,id,A          ;active window id, useful for some gestures
sendinput {lbutton up}         ;prevents drag box appearing when left/right rocking and gesturing eg. m-lr(d):
hotkey,lbutton,on              ;lbutton only tracked when other mouse buttons start tracking
hotkey,lbutton up,on
xpos1:=xpos,ypos1:=ypos
if not buttonsup
   settimer,gtrack,1           ;will go as fast as timer will allow, either 10 or 15.6ms       
return

mbutton up::
if wheel                       ;middle button clicks ignored when using wheel
   return
rbutton up::
lbutton up::
xbutton1 up::
xbutton2 up::
lastup:=a_thishotkey="xbutton2 up" ? "f" : substr(a_thishotkey,1,1)
stringreplace,buttonsdown,buttonsdown,%lastup%,,all
buttonsup:=true
settimer,gtrack,off            ;no more gesture tracking once a mouse button has been released
if not wheel and substr(mouseclick,0,1)=lastup
   gosub callmacro   
if not buttonsdown         
   gosub cleanup
return
     
callmacro:
macrorunning:=true
if autoreturn
   mousemove,xpos,ypos,1       ;return cursor to where gesture started
macro:="m-" . mouseclick . (gtrack ? "(" . gtrack . ")" : "") . (wheel ? "-" . wheel : "")
if demomode
   msgbox,,DEMO MODE,%macro%,1   
else
   if islabel(macro)         
         gosub %macro%
macrorunning:=false
return

gtrack:
mousegetpos xpos2,ypos2
angle:=abs((xpos1-xpos2)/(ypos1-ypos2+0.001))      ;+0.001 avoids divide by zero error
if (angle>0.7 and angle<1.428) or (abs(ypos1-ypos2)<5 and abs(xpos1-xpos2)<5)   ;ignores angles within 10 degrees of 45 degree diagonal
   return                                                                       ;ignores movement that is too slow
track1:=(abs(ypos1-ypos2)>abs(xpos1-xpos2)) ? (ypos1>ypos2 ? "u" : "d") : (xpos1>xpos2 ? "l" : "r")  ;determines up down left right
if (track1<>track2)            ;remembers mouse position when track direction changes
   xpos0:=xpos2,ypos0:=ypos2
if (track1<>SubStr(gtrack, 0, 1)) and (track1=track2) and (abs(xpos0-xpos2)>=mintrack or abs(ypos0-ypos2)>=mintrack) 
   gtrack.=track1        ;track if x or y changing sufficient to register. track needs confirmation (2 tracks same direction)
xpos1:=xpos2,ypos1:=ypos2,track2:=track1
return

cleanup:
if (win1<>windesktop)     
   win2:=win1     ; used in some gestures, win2 is the window the previous macro acted on
hotkey,lbutton,off             ; restore normal left mouse button function
hotkey,lbutton up,off
wheel:="",gtrack="",buttonsup="",mouseclick="",buttonsdown="",track2=""
return

wheelup::
wheeldown::
if instr(buttonsdown,"m") or macrorunning    ;prevents accidental use of mousewheel with middle button gestures   
   return   
if buttonsdown and not buttonsup
   {   
   wheel:=a_thishotkey
   settimer,gtrack,off   ;no more tracking once wheel used
   gosub callmacro
   }
if not buttonsdown
   sendinput {%a_thishotkey%}
return

esc::exitapp

m-r:                     ;normal right click
click right
return

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

;;;;;;; Examples ;;;;;;;;;;;;;;;;;;;;;;;;;;

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

;;;;; wheel examples ;;;;;;;;;;

m-r-wheelup:      ;change volume with wheel -  hold right button down and use wheel
Send {Volume_Up}
return

m-r-wheeldown:
Send {Volume_Down}
return

;;;;;;;; rocker examples ;;;;;;;;;;

m-rl:
msgbox,,,if you keep right held down, clicking left will repeat action,5
return

m-lr:                                           
msgbox,,,rocker left then right. careful where you click,5
return

m-rl(l):
m-lr(l):
msgbox,,,you combined rocking and gesturing,5
return

;;;;;;;;;;;; gesture examples ;;;;;;;;;;

m-r(u):             ;; gesture up ;; maximize window under cursor. maximize last window if cursor over desktop
if (win1=windesktop)
   {
   if (win2<>"")
   winmaximize, ahk_id %win2%
   }
else
   winmaximize ahk_id %win1%
return

m-r(d):            ;minimize window under cursor
if (win1<>windesktop)    ;don't minimize the desktop
   winminimize, ahk_id %win1%
return

m-r(l):            ;browser back
winactivate ahk_id %win1%   
sendinput {Browser_Back}
return

m-r(r):            ;browser forward
winactivate ahk_id %win1%   
sendinput {Browser_Forward}
return

m-r(dr):            ;restore last window.
winrestore ahk_id %win2%
return

m-r(ldr):            ;close window under cursor (draw a C)
if (win1<>windesktop)
   winclose ahk_id %win1%
return
Back to top
View user's profile Send private message
MainTrane



Joined: 13 Oct 2010
Posts: 41

PostPosted: Wed Feb 09, 2011 11:23 pm    Post subject: Personal customization Reply with quote

Hello & thanks for this script, it's a great piece of work Smile .
I'm trying to customize it for my needs. Mostly to get more out of the wheel & rocker gestures, while limiting the drag gesture.

  • I have a Logitech mice with Hyper-Scroll. When the wheel scrolls too fast for AHK I get an error message, 71 hotkeys have been recieved in ***milliseconds, which can cause all my mouse buttons to become unresponsive. Any fix possible?
  • Kill MButton drag-only gestures
    It conflicts with my only other AHK script DragToScroll; plus many other middle button uses.
    I've already returned the standard middle click function:
    Code:
    m-m:                     ;normal middle click
    sendinput {MButton}
    return
    Any advice on how to combine these two scripts into one, without one breaking the other, would also be much appreciated.
    NOTE: I've remapped my middle button away from the scroll wheel to one of the four side buttons on the G700.
  • Modifier Key Gestures for both wheel & rocker
    The other three G700 side buttons are mapped to the three modifier keys Ctrl, Alt, Shift.
    Code:
    ;;;;;;; Examples ;;;;;;;

    m-+-wheelup:                          ;shift and wheel switch tabs (firefox)
    winactivate ahk_id %win1%   
    sendinput ^{PGUP}
    return

    m-^r:                          ;ctrl then rbutton = file properties
    winactivate ahk_id %win1%   
    sendinput {RButton}r
    return

  • Other button wheel gestures
    Wheel gestures only apply to the RButton so far, but they'd be very useful with the other mouse buttons too!
    Code:
    ;;;;;;; Examples ;;;;;;;

    m-m-wheelup:                          ;MButton & wheel = top of page
    winactivate ahk_id %win1%   
    sendinput ^{Home}                     ;^{End} for wheeldown
    return

    m-l-wheelup:                          ;LButton & wheel = next song, video, etc.
    Send {Media_Next}
    return


I'm a complete newb *u* at coding, so any advice at all will be much appreciated.
Back to top
View user's profile Send private message
Guest






PostPosted: Thu Feb 10, 2011 1:37 pm    Post subject: Reply with quote

try
Code:
#MaxHotkeysPerInterval 200
try increasing or decreasing this setting. please let me know if you find a figure that works. the default is 70 so you're getting the message at 71
don't see how you could combine drag gesture with drag-scroll. don't think i'd want to
as to remapping your other mouse key, sounds a bit complicated. find out how you can address the key and add it to the list of keys. for eg, i had a logitech mx620 and it had a search button. that mouse button was sc165 (look up special keys - http://www.autohotkey.com/docs/KeyList.htm )
the script would look like this
Code:
lbutton::
rbutton::
mbutton::
sc165::
Code:
lbutton up::
rbutton up::
mbutton up::
sc165 up::


so a gesture up using this button would be m-s(u):

as to "wheel gestures only apply to Rbutton so far" that's not quite true. i've disabled wheel gestures when gesturing the middle button on purpose-to avoid errors. i might make it easier to disable this though. see ...
Code:
wheelup::
wheeldown::
if instr(buttonsdown,"m") or macrorunning    ;prevents accidental use of mousewheel with middle button gestures   
   return 

if you have a 4th mouse button, it's probably xbutton and you can then do m-x(wheelup):
I like the sound of m-l-wheelup: and will incorporate that in the next few days
Back to top
rodfell



Joined: 05 Oct 2007
Posts: 138
Location: Bundaberg (Bundy), Qld, Australia

PostPosted: Thu Feb 10, 2011 1:58 pm    Post subject: Reply with quote

wow g700 has 13 buttons. anyway, as i said above, each button will have its own name that autohotkey can directly address. trouble is if one is say sc165: and another is sc166: they'll both come across as just "s". i've solved this problem for xbutton and xbutton2 but i might come up with a more generic and therefore more flexible solution
Back to top
View user's profile Send private message
MainTrane



Joined: 13 Oct 2010
Posts: 41

PostPosted: Thu Feb 10, 2011 9:36 pm    Post subject: Reply with quote

Thanks for the reply rodfell, and for keeping this great script current!

Inserting #MaxHotkeysPerInterval 500 at line three seems to be enough of a buffer for Logitech's hyper scrolling Smile

I don't think you have to worry about special keys. I mapped all my buttons to recognizable keys using Logitech's Setpoint drivers.
Here are the only buttons I wan't the script to have an effect upon:
Code:
lbutton::
rbutton::
mbutton::
shift::
ctrl::
alt::
So the lettering isn't a problem, for my setup at least. I'm using 'l' 'r' 'm' 's' 'c' 'a' and would like all these buttons to have their standard function when normally pressed. I want to do wheel gestures with every single one of these buttons. No drag gesturing for any button, except 'r'. And here's the most complicated part. Rocker gestures with all of the above buttons; except that the modifier keys shouldn't interfere with each other in this script, keeping their standard modifier functions. For example no Ctrl-Alt, Shift-Ctrl, etc.. rocking gestures; 's' 'c' 'a' should only track when gesturing with the standard mouse buttons 'l' 'r' 'm' or the scroll wheel.

rodfell wrote:
as to "wheel gestures only apply to Rbutton so far" that's not quite true.
Sorry about that assumption, I don't have any XButtons in my setup and LButton and MButton weren't working with wheel gestures.

*There shoudn't be any conflict between the DragToScroll script and your Multi-Gesturing script. Seeing as I only want drag gestures with the RButton in your script, while the DragToScroll script is dedicated to the MButton. ASIDE: The scroll drag scipt already has a movement check and drag delay in place that prevents it from interfering with non-drag gestures.

I guess the easiest way to convey what I'm saying is; every button in MY configuration for this script, other than RButton, should track just like the LButton currently does, with the inclusion of basic wheel gestures.
Back to top
View user's profile Send private message
MainTrane



Joined: 13 Oct 2010
Posts: 41

PostPosted: Thu Feb 10, 2011 10:26 pm    Post subject: Reply with quote

rodfell wrote:
I like the sound of m-l-wheelup: and will incorporate that in the next few days
Great Very Happy

I've tried several edits to this multi-gesturing script. Seeing as my coding skills are RAW, I keep breaking some of it's functionality. To make helping me out easier on you, here's what I'm trying to do in bullets.

  • Turn off drag tracking for specific buttons
    - RButton is the only one I want to be tracked on mouse movement
  • Disble single press interception
    - currently tracks a standard press of any button other than LButton
    - assigning these buttons back to their standard value doesn't work fully
    Code:
    m-s:                     ;normal shift key
    sendinput {shift}
    return
    doesn't allow shift key to capitalize letters
  • No tracking between certain buttons
    - don't want tracking of rocking gestures between 's' 'c' 'a' 'l', they should still track with 'r' 'm'

If interacting with the modifier keys, without breaking their standard functions, is too complicated for this script I may have to find an alternative method of doing Shift+Wheel and Ctrl+MButton type gestures Confused .
Back to top
View user's profile Send private message
rodfell



Joined: 05 Oct 2007
Posts: 138
Location: Bundaberg (Bundy), Qld, Australia

PostPosted: Fri Feb 11, 2011 6:19 am    Post subject: Reply with quote

have added wheel-mouse functionality when just left button held down (ie. m-l-wheelup and m-l-wheeldown)
few other minor changes
Code:
demomode:=true     ;demonstration mode on/off. change to false when ready to use
mintrack=20      ;minimum length of registered track sector in pixels 
wheelguard:=true  ;set as desired. if true, wheel and middle button click can't both be used in the same gesture (recommended)

winget,windesktop,id,ahk_class Progman   ;desktop id, useful for some macros
gosub cleanup
return

xbutton2::   ;because xbutton1 and xbutton2 have the same first letter
thishotkey=f   ;   one of them has to be assigned a different letter
goto mousedown

xbutton2 up::
lastup=f
goto mouseup


mbutton::   ;list any mouse buttons to be named by first letter here eg. mbutton is "m"
lbutton::     
rbutton::     
xbutton1::
thishotkey:=substr(a_thishotkey,1,1)
mousedown:         
if macrorunning or wheel
   return
if not buttonsdown             
   mousegetpos xpos1,ypos1,win1  ;win1 is the window underneath the current gesture
mouseclick:=buttonsdown.=(not buttonsdown and getkeystate("lbutton") ? "l" : "") . thishotkey
winget,winactive,id,A          ;active window id, useful for some macros
sendinput {lbutton up}         ;prevents drag box appearing when left/right rocking and gesturing eg. m-lr(d):
hotkey,lbutton,on              ;lbutton only tracked when other mouse buttons start tracking
hotkey,lbutton up,on
if not buttonsup
   settimer,gtrack,1           ;will go as fast as timer will allow, either 10 or 15.6ms       
return

mbutton up::
if wheel and wheelguard        ;middle button clicks ignored when using wheel (if wheelguard=true)
   return
rbutton up::
lbutton up::
xbutton1 up::
lastup:=substr(a_thishotkey,1,1)
mouseup:
stringreplace,buttonsdown,buttonsdown,%lastup%,,all
buttonsup:=true
settimer,gtrack,off            ;no more gesture tracking once a mouse button has been released
if not wheel and substr(mouseclick,0,1)=lastup
   gosub callmacro   
if not buttonsdown         
   gosub cleanup
return
     
callmacro:
macrorunning:=true
macro:="m-" . mouseclick . (gtrack ? "(" . gtrack . ")" : "") . (wheel ? "-" . wheel : "")
if demomode
   msgbox,,DEMO MODE,%macro%,1   
else
   if islabel(macro)         
         gosub %macro%
macrorunning:=false
return

gtrack:
mousegetpos xpos2,ypos2
angle:=abs((xpos1-xpos2)/(ypos1-ypos2+0.001))      ;+0.001 avoids divide by zero error
if (angle>0.7 and angle<1.428) or (abs(ypos1-ypos2)<5 and abs(xpos1-xpos2)<5)   ;ignores angles within 10 degrees of 45 degree diagonal
   return                                                                       ;ignores movement that is too slow
track1:=(abs(ypos1-ypos2)>abs(xpos1-xpos2)) ? (ypos1>ypos2 ? "u" : "d") : (xpos1>xpos2 ? "l" : "r")  ;determines up down left right
if (track1<>track2)            ;remembers mouse position when track direction changes
   xpos0:=xpos2,ypos0:=ypos2
if (track1<>SubStr(gtrack, 0, 1)) and (track1=track2) and (abs(xpos0-xpos2)>=mintrack or abs(ypos0-ypos2)>=mintrack)
   gtrack.=track1        ;track if x or y changing sufficient to register. track needs confirmation (2 tracks same direction)
xpos1:=xpos2,ypos1:=ypos2,track2:=track1
return

cleanup:
if (win1<>windesktop)     
   win2:=win1     ; used in some gestures, win2 is the window the previous macro acted on
hotkey,lbutton,off             ; restore normal left mouse button function
hotkey,lbutton up,off
wheel:="",gtrack="",buttonsup="",mouseclick="",buttonsdown="",track2=""
return

wheelup::
wheeldown::
if (instr(buttonsdown,"m") and wheelguard) or macrorunning    ;prevents accidental use of mousewheel with middle button gestures   
   return
mouseclick:=buttonsdown.=(not buttonsdown and getkeystate("lbutton") ? "l" : "")
if buttonsdown and not buttonsup
   {   
   wheel:=a_thishotkey
   settimer,gtrack,off   ;no more tracking once wheel used
   gosub callmacro
   }
if not buttonsdown
   sendinput {%a_thishotkey%}
return

esc::exitapp

m-r:                     ;normal right click
sendinput {rbutton}
return

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

;;;;;;; Examples ;;;;;;;;;;;;;;;;;;;;;;;;;;

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

;;;;; wheel examples ;;;;;;;;;;

m-r-wheelup:      ;change volume with wheel -  hold right button down and use wheel
Send {Volume_Up}
return

m-r-wheeldown:
Send {Volume_Down}
return

;;;;;;;; rocker examples ;;;;;;;;;;

m-rl:
msgbox,,,if you keep right held down, clicking left will repeat action,5
return

m-lr:                                           
msgbox,,,rocker left then right. careful where you click,5
return

m-rl(l):
m-lr(l):
msgbox,,,you combined rocking and gesturing,5
return

;;;;;;;;;;;; gesture examples ;;;;;;;;;;

m-r(u):             ;; gesture up ;; maximize window under cursor. maximize last window if cursor over desktop
if (win1=windesktop)
   {
   if (win2<>"")
   winmaximize, ahk_id %win2%
   }
else
   winmaximize ahk_id %win1%
return

m-r(d):            ;minimize window under cursor
if (win1<>windesktop)    ;don't minimize the desktop
   winminimize, ahk_id %win1%
return

m-r(l):            ;browser back
winactivate ahk_id %win1%   
sendinput {Browser_Back}
return

m-r(r):            ;browser forward
winactivate ahk_id %win1%   
sendinput {Browser_Forward}
return

m-r(dr):            ;restore last window.
winrestore ahk_id %win2%
return

m-r(ldr):            ;close window under cursor (draw a C)
if (win1<>windesktop)
   winclose ahk_id %win1%
return
Back to top
View user's profile Send private message
Display posts from previous:   
Reply to topic    AutoHotkey Community Forum Index -> Scripts & Functions All times are GMT
Goto page Previous  1, 2, 3, 4, 5, 6, 7, 8  Next
Page 5 of 8

 
Jump to:  
You can post new topics in this forum
You can reply to topics in this forum


Powered by phpBB © 2001, 2005 phpBB Group