Key Press/Held Command

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
subzero
Posts: 12
Joined: 03 Apr 2021, 18:46

Key Press/Held Command

18 May 2021, 07:57

I would like a script that when I press F12 it will open a URL and when I hold down F12 for 0.5 seconds it will open notepad instead of the URL. I've got this partially working, but I can't figure out how to prevent it opening the URL when it is held down to open notepad. My attempt for your consideration is below.

Code: Select all

$F12::
   Run https://www.autohotkey.com
   KeyWait,F12,T0.5 ;wait 0.5 seconds for release key
   If (ErrorLevel) ;more than 0.5 sec have passed
   {
   Run C:\Windows\System32\Notepad
   KeyWait,F12 ;prevent launching URL after notepad opened
   }
    Return
Last edited by joedf on 18 May 2021, 08:15, edited 1 time in total.
Reason: added [code] tags
User avatar
mikeyww
Posts: 26889
Joined: 09 Sep 2014, 18:38

Re: Key Press/Held Command

18 May 2021, 08:22

Code: Select all

F12::
KeyWait, F12, T.5
Run, % ErrorLevel ? "notepad.exe" : "https://www.autohotkey.com/"
KeyWait, F12
Return
subzero
Posts: 12
Joined: 03 Apr 2021, 18:46

Re: Key Press/Held Command

18 May 2021, 20:12

mikeyww wrote:
18 May 2021, 08:22

Code: Select all

F12::
KeyWait, F12, T.5
Run, % ErrorLevel ? "notepad.exe" : "https://www.autohotkey.com/"
KeyWait, F12
Return
thanks, thats worked!
subzero
Posts: 12
Joined: 03 Apr 2021, 18:46

Re: Key Press/Held Command

18 May 2021, 21:08

I would also like a variation on this, where instead of launching notepad, it presses "F11", is this possible?
User avatar
mikeyww
Posts: 26889
Joined: 09 Sep 2014, 18:38

Re: Key Press/Held Command

18 May 2021, 21:43

Code: Select all

F12::
KeyWait, F12, T.5
If ErrorLevel
 Send {F11}
Else Run, https://www.autohotkey.com/
KeyWait, F12
Return
subzero
Posts: 12
Joined: 03 Apr 2021, 18:46

Re: Key Press/Held Command

20 May 2021, 02:55

mikeyww wrote:
18 May 2021, 21:43

Code: Select all

F12::
KeyWait, F12, T.5
If ErrorLevel
 Send {F11}
Else Run, https://www.autohotkey.com/
KeyWait, F12
Return
worked, thanks again!

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: Chunjee, scriptor2016 and 280 guests