How do I make a script work ONLY when a button is NOT being held down Topic is solved

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
xtreyreader
Posts: 3
Joined: 24 Jan 2022, 20:18

How do I make a script work ONLY when a button is NOT being held down

Post by xtreyreader » 24 Jan 2022, 20:33

Hello kind humans, I want the following:

I press the windows left key, A happens.
I press and hold the windows left key, normal windows stuff happens.

So for example, if I press LWin a program starts, but if I press Lwin+Shift+S a normal windows screeenshot happens.
I already have the 'A happens' part covered, but I need a way to let AHS know "yeah look if I hold this key more than X ms then forget about opening anything thank you".

This is my script:

Code: Select all

lwin::
Send {LAlt down}{Space}{LAlt up}
return
PD: The program is Launchy, which replaces the search and run stuff you usually do with the windows key, and Launchy is launched by alc+space in default options.

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

Re: How do I make a script work ONLY when a button is NOT being held down

Post by mikeyww » 24 Jan 2022, 20:49

Possibly:

Code: Select all

~LWin Up::
If (A_PriorKey != "LWin")
 Return
Send {Esc}
Run, notepad.exe
Return
There may be better ways!

xtreyreader
Posts: 3
Joined: 24 Jan 2022, 20:18

Re: How do I make a script work ONLY when a button is NOT being held down

Post by xtreyreader » 25 Jan 2022, 07:25

Hello and thank you, that code almost works. Now the problem is, when I press LWin the start menu appears for a moment in a glitched fast fashion and sometimes it keeps itself open. And that happens because windows recognizes LWin before AHK {Lwin up}. Do you know any fix for that? Thank you again kind human being.

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

Re: How do I make a script work ONLY when a button is NOT being held down  Topic is solved

Post by mikeyww » 25 Jan 2022, 07:44

Possibly:

Code: Select all

LWin::
KeyWait, LWin, T.2
If ErrorLevel { ; Held
 Send {LWin down}
 SoundBeep, 1500
 KeyWait, LWin
 Send {LWin up}
} Else Run notepad.exe
SoundBeep, 1000
Return

xtreyreader
Posts: 3
Joined: 24 Jan 2022, 20:18

Re: How do I make a script work ONLY when a button is NOT being held down

Post by xtreyreader » 25 Jan 2022, 08:17

mikeyww wrote:
25 Jan 2022, 07:44
Possibly:

Code: Select all

LWin::
KeyWait, LWin, T.2
If ErrorLevel { ; Held
 Send {LWin down}
 SoundBeep, 1500
 KeyWait, LWin
 Send {LWin up}
} Else Run notepad.exe
SoundBeep, 1000
Return
It looks like that did the trick, thank you very much. In case anyone need specifically the code I use:

Code: Select all

LWin::
KeyWait, LWin, T.2
If ErrorLevel { ; Held
 Send {LWin down}
 KeyWait, LWin
 Send {LWin up}
} Else Send {LAlt down}{Space}{LAlt up}
Return

Post Reply

Return to “Ask for Help (v1)”