Sending key combo to application

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
mhyder1
Posts: 11
Joined: 30 Sep 2022, 16:18

Sending key combo to application

Post by mhyder1 » 30 Sep 2022, 16:29

I have an application that uses a special keyboard. The keyboard has several key combinations configured into it such at ctrl+shift+alt+s. The application is programmed to respond to the key combinations and run functions based on the combo. Im using AHK so that we can bring the application into focus when a key is pressed. Here is what I want to happen
1. When a key combination is pressed bring the application to the front (I have this working)

Code: Select all

^+!s::
   WinActivate, Treasury
   Send ^+!s  // not working
return
That translates to: when ctrl+shift+alt+s is pressed, bring the window with Treasury title to the foreground
2. trigger the same key combination so that it will be activated in the application. In the script I'm trying to send the same keys but they are not registering in the app.
Nothing happens.

I just wanted to verify if my approach is incorrect or if maybe what I'm trying to do is not possible with AHK. Thanks in advance for any help

User avatar
boiler
Posts: 16951
Joined: 21 Dec 2014, 02:44

Re: Sending key combo to application

Post by boiler » 30 Sep 2022, 17:07

You can add WInWaitActive to make sure it's active before it's sent (I usually add it anyway even though the documentation says it's not usually necessary). And you should precede your hotkey with a $ so it doesn't trigger itself when you send the same key combination.

Code: Select all

$^+!s::
   WinActivate, Treasury
   WinWaitActive, Treasury
   Send ^+!s ; semicolon is the comment delimiter, not "//"
return

mhyder1
Posts: 11
Joined: 30 Sep 2022, 16:18

Re: Sending key combo to application

Post by mhyder1 » 30 Sep 2022, 17:57

Thank you so much. That worked perfectly.
Now to clean things up. I have many keys that follow that same pattern. Is there anyway to the script or do I just need to repeat that section several times:

Code: Select all

$^+!s::
    WinActivate, Treasury
    WinWaitActive, Treasury
    Send ^+!s
return
$^+!r::
   WinActivate, Treasury
   WinWaitActive, Treasury
   Send ^+!r
return
etc...

User avatar
boiler
Posts: 16951
Joined: 21 Dec 2014, 02:44

Re: Sending key combo to application

Post by boiler » 30 Sep 2022, 18:28

You could do this:

Code: Select all

$^+!r::
$^+!s::
    WinActivate, Treasury
    WinWaitActive, Treasury
    Send, % SubStr(A_ThisHotkey, 2) ; strips off the $
return

mhyder1
Posts: 11
Joined: 30 Sep 2022, 16:18

Re: Sending key combo to application

Post by mhyder1 » 02 Oct 2022, 22:02

Awesome!! Works perfectly.
One last thing. I have a couple key combinations that use the plus symbol.
So it looks like:

Code: Select all

$^+!+
Evidently I want {Ctrl}{Shift}{Alt} and the plus symbol
I tried

Code: Select all

$^+!{+}
after some basic research but it wont compile.
I also need to use the semicolon which I know is for comments.
I read that you could escape characters with a backtick `.
Thanks for any help.

User avatar
boiler
Posts: 16951
Joined: 21 Dec 2014, 02:44

Re: Sending key combo to application

Post by boiler » 02 Oct 2022, 23:03

The first one should work. Did you put :: after it? It needs to be shifted just to produce the + on my keyboard, so shifting a + is redundant. Does your keyboard not require it to be shifted to produce a +? (mine is a shifted =) You’re not referring to the + on the NumPad, are you? If you can’t get it to work using the + symbol, you can also check out Special Keys to find the code for that key and create a hotkey for it.


For the semicolon, just escape it as you suggested `;::. Instead of asking if it will work, why not try it out and see for yourself?

Post Reply

Return to “Ask for Help (v1)”