Mouse movement => send "a" hold press And mouse stop move => send release "a" press.

Ask gaming related questions (AHK v1.1 and older)
realdreamer
Posts: 2
Joined: 26 Jan 2024, 23:23

Mouse movement => send "a" hold press And mouse stop move => send release "a" press.

Post by realdreamer » 26 Jan 2024, 23:35

My question is in the subject, how to accomplish that.

I will use this to navigate in flying (3D)
current setup: when character already move, to change direction is to move mouse cursor + hold press "a".
I want to automatic the hold press "a", so only move the cursor equal to change direction.

Rohwedder
Posts: 7773
Joined: 04 Jun 2014, 08:33
Location: Germany

Re: Mouse movement => send "a" hold press And mouse stop move => send release "a" press.

Post by Rohwedder » 27 Jan 2024, 03:13

Hallo,
try:

Code: Select all

q Up:: ; ADown while Mouse movement (on/off)
ADown?(DllCall("UnhookWindowsHookEx", "Ptr", ADown), ADown := "")
	:ADown := DllCall("SetWindowsHookEx", "UInt", 14, "Ptr"
	, RegisterCallback("LowLevelMouseProc"), "Ptr", 0, "UInt", 0, "Ptr")	
LowLevelMouseProc(nCode, wParam, lParam) {
    If (wParam = 0x0200) { ; WM_MOUSEMOVE
		SendEvent,% ["{Blind}{a Down}"][!GetKeyState("a")]
		SetTimer, AUp, -50 ; release 50 ms after the last Mouse movement
}} AUp() {
	SendEvent, {Blind}{a Up}
} Return

realdreamer
Posts: 2
Joined: 26 Jan 2024, 23:23

Re: Mouse movement => send "a" hold press And mouse stop move => send release "a" press.

Post by realdreamer » 27 Jan 2024, 15:26

Hi, thanks for the answer.
Tested it.
It partially working, need tweaking something.
But why it continous sending {a up} after toggle the hotkey off?

Rohwedder
Posts: 7773
Joined: 04 Jun 2014, 08:33
Location: Germany

Re: Mouse movement => send "a" hold press And mouse stop move => send release "a" press.

Post by Rohwedder » 28 Jan 2024, 02:43

Definitely not happens here!
With {a Down} and {a Up} Tooltips:

Code: Select all

q Up:: ; ADown while Mouse movement (on/off)
ADown?(DllCall("UnhookWindowsHookEx", "Ptr", ADown), ADown := "")
	:ADown := DllCall("SetWindowsHookEx", "UInt", 14, "Ptr"
	, RegisterCallback("LowLevelMouseProc"), "Ptr", 0, "UInt", 0, "Ptr")	
LowLevelMouseProc(nCode, wParam, lParam) {
    If (wParam = 0x0200) { ; WM_MOUSEMOVE
		SendEvent,% ["{Blind}{a Down}"][Now:=!GetKeyState("a")]
		Now?ToolTip(A_TickCount ": {a Down}",100,100,1):""
		SetTimer, AUp, -50 ; release 50 ms after the last Mouse movement
}} AUp() {
	SendEvent, {Blind}{a Up}
	ToolTip(A_TickCount ": {a Up}",100,130,2)
} Return
ToolTip(Text:="", X:="", Y:="", WhichToolTip:=1) {
    ToolTip,% Text,% X,% Y,% WhichToolTip
}

Post Reply

Return to “Gaming Help (v1)”