Need Help with a Conditional Script

Ask gaming related questions
kry_tl
Posts: 2
Joined: 30 May 2023, 14:51

Need Help with a Conditional Script

Post by kry_tl » 30 May 2023, 15:05

I am new to AHK and coding in general.

I'm trying to write a script that disables or rebinds Numpad4 only while RMB Is being held down. Upon releasing RMB, Numpad4 should revert back to normal function.

The code I am trying is as follows:

Code: Select all

if WinActive("my_game.exe")
	if GetKeyState("RButton", "P") {
		Numpad4::LButton
		}
	return
The problem I am facing is when RMB is released/not pressed at all, Numpad4 doesn't revert to normal but stays bound to LButton. I suspect the conditional is not working but I could be missing something.

Appreciate some assistance.

User avatar
mikeyww
Posts: 26600
Joined: 09 Sep 2014, 18:38

Re: Need Help with a Conditional Script

Post by mikeyww » 30 May 2023, 19:38

Welcome to this AutoHotkey forum!

Hotkeys defined via :: are not subject to If, but you can use #HotIf.

Code: Select all

#Requires AutoHotkey v2.0
winTitle := 'ahk_exe notepad.exe'
#HotIf WinActive(winTitle) && GetKeyState('RButton', 'P')
Numpad4::LButton
#HotIf
Read: WinTitle

Explained: #HotIf

kry_tl
Posts: 2
Joined: 30 May 2023, 14:51

Re: Need Help with a Conditional Script

Post by kry_tl » 31 May 2023, 20:36

That worked like a charm.

Thank you very much.

Post Reply

Return to “Gaming”