Pages

2024/08/06

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

Finally, I have found the code that works.

 

 

The test steps – AutoHotkey 2.0.18

OS: Windows 11 Home

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

 

1. Download it from a link above and install.

 

2. The code.

 

#IfWinActive ahk_exe Notepad.exe

$a::

KeyWait,a

KeyWait,a,D T0.04

If ErrorLevel

               Send a

else

               Send x

return

#IfWinActive

 

 

Code explanation

 

Line 1: Notepad.exe is an active app. To get name of active app, read my previous post -- https://windowsfreewareguide.blogspot.com/2024/07/autohotkey-free-send-actions-from.html

 

Line 2: I use one key, in this code is a. If you want to use other letters (b,c,d,e...), just change it.

 

Line 3: replace a after , to your letter.

 

Line 4: replace a after , to your letter.

D T0.04 = waits for 0.04 secs for key a to be pressed down.

 

In this code if I press key a one time, it sends a. If I press key a twice while 'Notepad' is active, it sends x. If you type fast and set D T to D T3, what will happen is when you type 'ab' you'll get 'ba' because it waits for 3 secs then key a will be pressed.

 


Time in D T affects double pressing too. If you set D T to D T0.04 but you double press key a too slow, what you get is aa not x.

 


So you might want to do lots of testing in order to make no mistake.

 

Line 6: replace a to your letter.

 

Line 8: replace x to your action.

 

If you want this script to work on every active application, just delete the first and the last line.

 

3. To run script, read step 2 in my post -- https://windowsfreewareguide.blogspot.com/2024/07/send-key-sequences-after-key-is-held.html

 

4. You can send key combination (Ctrl+x,....) as an action. If you don't want to read the offical manual, you can read my post from a link above.

 

To open an application, replace line 8 with Run "wordpad". In this case 'Wordpad' is launched.

 

More details: https://www.autohotkey.com/docs/v2/howto/RunPrograms.htm

 

The manual says Run command can also be used to open documents, folders and URLs.

 

Not bad for 10-line code that will make my flow faster.

 


The test steps – AutoHotkey 2.0.18

OS: Windows 11 Home

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

No comments: