Aaron Franke
Aaron Franke

Reputation: 4022

Trigger AHK script based on the position of the mouse

Is it possible to trigger an AHK script based on the position of the mouse? Say, if I wanted to press a button or series of buttons on my keyboard if I move my mouse to the corner or edge of the screen. Also, can this be done multiple times per second until the mouse is moved out of the specified area?

All I could find from googling is AHK scripts for moving the mouse using the keyboard, when I want to do the opposite.

Upvotes: 4

Views: 1604

Answers (2)

shinzou
shinzou

Reputation: 6192

I did it, thanks Aaron and ahkcoder.

I got a little better feel with Up and Down instead of PgUp and PgDn, to anyone else, play with the timings until it's sufficient. You'll also need to modify the values for the edges of your screen.

; move up and down when mouse is at edges of screen
#Persistent
SetTimer, foo, 65
return

foo:
MouseGetPos, x, y, id, control
; ToolTip, %x% %y%
; will trigger only at edges of a full screen
if (y = 1087){
; bottom
send {Down}
send {Down}
send {Down}
; sleep, 300
}
else if(y = 8){
; top
send {Up}
send {Up}
send {Up}
}

return

Upvotes: 3

errorseven
errorseven

Reputation: 2672

Yes. Easiest way I can think of to do what you are asking is to use SetTimer and MouseGetPos to evaluate the position and if it matches than trigger your script.

The 2nd example code on the MouseGetPos is using SetTimer. This should get you headed in the right direction.

Upvotes: 2

Related Questions