Pages

2024/07/16

AutoHotkey (FREE) - Send Actions from Holding a Key for Specific Application

If you don’t have basic knowledge on coding to send an action after holding a key, you might want to read my previous post

 


What I do is get name/process of target application then put it in the script.

 

NOTE: After I’ve done writing this post, I uninstalled version 1.1.34.04, then downloaded and installed version 2.0.18 to test scripts.

 


After I opened the script ‘get active app name’, the message said to run the script, I need version 1.


I clicked ‘Yes’ to download and install version 1.1.37.2.

 


The script worked fine. Then I tested a script that can send action from holding a key for specific application which is mentioned in this post. It worked fine too.

 

This confusing part is in ‘Add or Remove Programs’ of Windows 11 only shows version 2.0.18. I might uninstall AutoHotkey and install version 1.1.37.2 to know for sure that a script I test is for version 1 or 2.

 

The test steps – AutoHotkey 1.1.34.04

OS: Windows 11 Home

Download: https://www.autohotkey.com/

 

1. Download it from a link above and install.

 

2. Thanks to AutoHotkey forum, I got this code to get name of active application.

 

F1::

Winget,AppName,ProcessName,A

MsgBox,% AppName

 

Run the script above, then activate a target application window, then press F1. The message shows a name of active application.

 


In my case is Explorer.EXE.

 

$x::

aDown:=A_TickCount

Keywait x

Duration:=(A_TickCount-aDown)

If (Duration>800)

Send {Delete}

Else

Send x

Return

 

The code above send an action after holding  a key ‘x’ longer than 800 milliseconds which is mentioned in my previous post – add link.

What I do is change line 5 to:

 

If (Duration>800) and WinActive("ahk_exe Explorer.EXE")

 

From now on, if application ‘Explorer.EXE’ is not active, an action is not sent.

 


The test steps – AutoHotkey 1.1.34.04

OS: Windows 11 Home

Download: https://www.autohotkey.com/

 

 

No comments: