keypress linked to mouse movement

Get help with using AutoHotkey and its commands and hotkeys
crinklecut
Posts: 2
Joined: 11 Jun 2019, 16:15

keypress linked to mouse movement

11 Jun 2019, 16:24

I would like to create a script that detects side to side (x) mouse movement and will press a corresponding key.

i.e. start to move mouse left, keypress and hold key "A". Mouse stops or moves right, key release "A". Start to move mouse right, keypress and hold key "B". Mouse stops or moves left, key release "B".

Could this be done? Any ideas how to do it?
Rohwedder
Posts: 2339
Joined: 04 Jun 2014, 08:33
Location: Germany

Re: keypress linked to mouse movement

12 Jun 2019, 01:49

Hallo,
try:

Code: Select all

F6:: ;On/Off with key F6
IF Toggle := !Toggle
{
	MouseGetPos, XOld
	SetTimer, MouseTimer, 100
}
Else
	SetTimer, MouseTimer, Off
Return
MouseTimer:
MouseGetPos, X
Key =
IF (X < XOld)
	Key = a
Else If (X > XOld)
	Key = b
XOld := X
If (Key = KeyOld)
	Return
IF KeyOld
	Send, {%KeyOld% Up}
IF KeyOld := Key
	Send, {%Key% Down}
Return
crinklecut
Posts: 2
Joined: 11 Jun 2019, 16:15

Re: keypress linked to mouse movement

12 Jun 2019, 05:02

Thanks! That's way better than my pitiful attempt.

Return to “Ask For Help”

Who is online

Users browsing this forum: anaxio, asad41163, Bing [Bot], Google [Bot] and 201 guests