Mouse Movement To Send a Key press

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
akrahaMacro
Posts: 2
Joined: 16 May 2022, 08:41

Mouse Movement To Send a Key press

Post by akrahaMacro » 16 May 2022, 10:18

Hello, I have this script viewtopic.php?t=65335 that I found on this very awesome forum, it basically detects mouse movement and translates it to a keypress, so for my case I want it to be active/working only when I'm pressing a given key (let's say 'F6' as an example) which would be acting as a toggle (On) while pressing and (Off) while releasing, as you can see the script in question (the one i found) only works with right and left detection, it would be more beneficial if it can also work Up and Down, now this script is supposed to hold press a specific key when moving in a direction (it does it nicely no complaints) but i want another version that sends repetitive key presses, for example, the more i move my mouse in the right or left or up/down direction the more it presses a specific key (repetitively), however, i should point out that when i tested the script, i found that when moving the mouse really slow it presses ( depending on the keys you assigned ) repetitively, but in that speed (really slowly) it really becomes none usable.

This script is to be used on many creative applications (adobe and such) so it would really help a lot of peeps in the future who will search for something like this, therefore I'm really grateful for any attempt :)

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 = Numpad4   ;left direction 
Else If (X > XOld)
        
	Key = Numpad6   ;right direction
XOld := X
If (Key = KeyOld)
	Return
IF KeyOld
	Send, {%KeyOld% Up}
IF KeyOld := Key
	Send, {%Key% Down}
Return

akrahaMacro
Posts: 2
Joined: 16 May 2022, 08:41

Re: Mouse Movement To Send a Key press

Post by akrahaMacro » 17 May 2022, 04:13

i managed to make it Work as long you press a key, (Holding presse), still to make it to detect Up and down cause it's only works Right and left.

Code: Select all

F6::
Send {F6 down}

	MouseGetPos, XOld
	SetTimer, MouseTimer, 100

KeyWait F6
Send {F6 up}

SetTimer, MouseTimer, Off
return

MouseTimer:
MouseGetPos, X
Key =
IF (X < XOld)
        
	Key = a   ;left direction 
Else If (X > XOld)
        
	Key = b   ;right direction
XOld := X
If (Key = KeyOld)
	Return
IF KeyOld
	Send, {%KeyOld% Up}
IF KeyOld := Key
	Send, {%Key% Down}
Return



Post Reply

Return to “Ask for Help (v1)”