AutoHotKey Send Dynamic Key

I'm trying to create a script with a user-configurable hotkey

I can bind to the dynamic hotkey, but I can't seem to send a hotkey.

Here is a simple script illustrating the problem

#Persistent #SingleInstance, Force btn1 := "F1" btn5 := "F5" Hotkey, %btn1% Up, stop1 Hotkey, %btn5% Up, stop5 stop1() { MsgBox f1 was released, sending f1 dynamically Send {%btn1%} } stop5() { MsgBox f5 was released, sending f1 statically Send {F1} } 

If I press F1, it triggers start1, and attempts to send F1 dynamically, as it's set in the header of the script. Nothing happens.

If I press F5, it triggers start5, and sends F1 statically. If your focused program uses that binding, the command is executed.

In my actual script, I need to be able to Send {%btn1% up} and Send {%btn1% down}

1 Answer

This version of your script works for me:

#Persistent btn1 := "F1" btn5 := "F5" Hotkey, %btn1% up, stop1 Hotkey, %btn5% up, stop5 return stop1: MsgBox f1 was released, sending f1 dynamically Send {%btn5%} return stop5: MsgBox f5 was released, sending f1 statically Send {F1} return 

You are mostly missing the return commands.

3

Your Answer

Sign up or log in

Sign up using Google Sign up using Facebook Sign up using Email and Password

Post as a guest

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

You Might Also Like