Hotkey function that does different routines if another key is pressed or released Topic is solved

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
astute65_aardvark20
Posts: 43
Joined: 23 Dec 2022, 18:59

Hotkey function that does different routines if another key is pressed or released

Post by astute65_aardvark20 » 13 Feb 2023, 02:31

I've got this hotkey routine so far:

Code: Select all

w::
Send, {w Down}
If (GetKeyState("LShift", "P"))
	Send, {LShift}
Return
Is there a way to make this routine also do

Code: Select all

Send, {w Up}
Sleep, 30
Send, {w Down}
If "LShift" is released, and do it within the "w::" hotkey function?

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

Re: Hotkey function that does different routines if another key is pressed or released  Topic is solved

Post by mikeyww » 13 Feb 2023, 07:36

:arrow: Else can be used in conjunction with If. KeyWait will wait for a key press or release if needed.

astute65_aardvark20
Posts: 43
Joined: 23 Dec 2022, 18:59

Re: Hotkey function that does different routines if another key is pressed or released

Post by astute65_aardvark20 » 14 Feb 2023, 02:00

When I tried over and over to use KeyWait, LShift with Else If statements, I couldn't get it to work... :headwall: Not sure what I was doing wrong. I went back to the original script, stared at it for a while, then the light bulb went on:

Code: Select all

w::
Send, {w Down}
While (GetKeyState("w", "P")) {
    If (GetKeyState("LShift", "P")) {
        Send, {LShift Down}
        KeyWait, LShift, L
        Send, {LShift Up}{w Up}
        Sleep, 30
        Send, {w Down}
    }
}
Return
Is this what you had in mind all along, or did you have a totally different method? It does work, so yay!

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

Re: Hotkey function that does different routines if another key is pressed or released

Post by mikeyww » 14 Feb 2023, 07:38

I actually have no idea what the script should do, because you provided no description. Great if it works! :thumbup: :wave:

Post Reply

Return to “Ask for Help (v1)”