Page 1 of 1

keypress linked to mouse movement

Posted: 11 Jun 2019, 16:24
by crinklecut
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?

Re: keypress linked to mouse movement

Posted: 12 Jun 2019, 01:49
by Rohwedder
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

Re: keypress linked to mouse movement

Posted: 12 Jun 2019, 05:02
by crinklecut
Thanks! That's way better than my pitiful attempt.