4

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.

2 Answers 2

3

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
Sign up to request clarification or add additional context in comments.

Comments

2

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.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.