Hold down hotkey Topic is solved

Ask gaming related questions (AHK v1.1 and older)
banhmikem
Posts: 4
Joined: 18 May 2022, 01:17

Hold down hotkey

Post by banhmikem » 18 May 2022, 01:24

Hi guys, i somehow manage to learn how to create autohotkey script but the problem occured, as following.
I tried to make a script that whenever i press SHIFT , it will be come SHIFT + Z (hold down until release) with this:

Code: Select all

~LShift::
KeyDown := !KeyDown
    While (GetKeyState("LShift", "p")){
        Send, {Shift down}{z down}
        Sleep 100
    }
However, the problem is it keeps pressing Z (i dont know what it keeps (only Z or both Shift Z) after i release the SHIFT button, can anyone help me please :(
Last edited by BoBo on 18 May 2022, 03:07, edited 1 time in total.
Reason: Moved to Gaming section.

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

Re: Hold down hotkey  Topic is solved

Post by Rohwedder » 18 May 2022, 02:39

Hallo,
try:

Code: Select all

~LShift::
While (GetKeyState("LShift", "p"))
{
	Send, {LShift down}{z down}
	Sleep 100
}
Send, {LShift up}{z up}
Return
Run this as a second script to see the states of the Keys := "LShift z"

Code: Select all

#Persistent
OnExit("KeysReset")
;KeyStateTimer shows the logical State of Keys
SetTimer, State, 200, Keys := "LShift z"
State: ;Keys separated with space or tab
For all,Key in StrSplit(Keys,[A_Space,A_Tab])
	Text.=Trim(Key)>""?"`n" Key "`t" (GetKeyState(Key)?"down":"up"):
MouseGetPos, MX, MY ;separated from another ToolTip
ToolTip,% SubStr(Text,2),MX+16,MY+32,4,Text:=""
Return
KeysReset()
{
	Loop, 0xFF
		IF GetKeyState(Key:=Format("VK{:X}",A_Index))
			SendInput, {%Key% up}
	ExitApp
}

banhmikem
Posts: 4
Joined: 18 May 2022, 01:17

Re: Hold down hotkey

Post by banhmikem » 18 May 2022, 02:54

Rohwedder wrote:
18 May 2022, 02:39
Hallo,
Hi mate, it works well with my notepad, will test in game later when i have a chance, thank you ^^

banhmikem
Posts: 4
Joined: 18 May 2022, 01:17

Re: Hold down hotkey

Post by banhmikem » 18 May 2022, 05:37

Rohwedder wrote:
18 May 2022, 02:39
Hallo,
Hi mate,
image.png
image.png (11.12 KiB) Viewed 569 times
As i use the second script, it works well on destop or notepad, but i cannot use it in game, the z stay up still even i press Shift. However i can use my old script, but the problem, that the z is kept pressed...
Attachments
image.png
image.png (11.12 KiB) Viewed 569 times

banhmikem
Posts: 4
Joined: 18 May 2022, 01:17

Re: Hold down hotkey

Post by banhmikem » 18 May 2022, 06:44

ah, nevermind that, i found it is related to version of window, it works well with window 7 now, thank you bro ^^

Post Reply

Return to “Gaming Help (v1)”