AHK script to work when a key is pressed for some time

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
monatilda23
Posts: 26
Joined: 25 Jan 2022, 10:24

AHK script to work when a key is pressed for some time

Post by monatilda23 » 25 Jan 2022, 11:49

Hello AHK, I cant understand how to make a script not work instantly when a key is pressed, but when I have the key pressed for 5 seconds. :geek:
The other problem is that the original key must work as usual on quick click.

For example, I need Win key to be a CTRL + C, only if I have WIN key pressed for 5 sec

Is it possible?
thanks


monatilda23
Posts: 26
Joined: 25 Jan 2022, 10:24

Re: AHK script to work when a key is pressed for some time

Post by monatilda23 » 25 Jan 2022, 12:02

cheers @mikeyww, Thanks for your reply. I've seen this topic from Google Search already. The problem for me is that I need the opposite result, but being newbie to AHK I don't understand what exactly needs to be changed from that proposed script unfortunately

monatilda23
Posts: 26
Joined: 25 Jan 2022, 10:24

Re: AHK script to work when a key is pressed for some time

Post by monatilda23 » 25 Jan 2022, 12:50

UPD
___

from abovementioned topic I composed a script for my needs

Code: Select all

LWin::
KeyWait, LWin, T.2
If ErrorLevel { ; Held
 Send #{Left}
 SoundBeep, 8000
 KeyWait, LWin
 Send {LWin up}
} Else  Send {LWin down}
 Send {LWin up}
SoundBeep, 1000
Return
the problem is that when I need to enter Win + V menu (clipboard) the script doesn't let me, looks like it recognizes the Win pressed as part of script. I changed the value for 8000 but anyway it works too fast.

what can be the problem ?

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

Re: AHK script to work when a key is pressed for some time

Post by mikeyww » 25 Jan 2022, 13:27

Perhaps:

Code: Select all

LWin::
Input, key, L1T5, % "{F1}{F2}{F3}{F4}{F5}{F6}{F7}{F8}{F9}{F10}{F11}{F12}"
                  . "{Left}{Right}{Up}{Down}{Home}{End}{PgUp}{PgDn}"
                  . "{Del}{Ins}{BS}{CapsLock}{NumLock}{PrintScreen}{Pause}"
mods := (GetKeyState("Ctrl" , "P") ? "^" : "")
      . (GetKeyState("Alt"  , "P") ? "!" : "")
      . (GetKeyState("Shift", "P") ? "+" : "")
SoundBeep, 1500
If (ErrorLevel = "Timeout") ; LWin was held
 Send ^c
Else Send % "#" mods "{" (key > "" ? key : StrReplace(ErrorLevel, "EndKey:")) "}"
KeyWait, LWin
Return

Post Reply

Return to “Ask for Help (v1)”