5

I want to send a key which is held in a variable down. The reason it is held in a variable is because I use a gui for the user to input the key in question.

Currently this works:

Send %hotkey%

But this doesn't:

Send {%hotkey% down}

How can I make this work properly?

Stevoisiak
  • 23,794
  • 27
  • 122
  • 225
Paul Chambers
  • 311
  • 1
  • 6
  • 13

2 Answers2

4

Try this code:

Version 1:

hotkey := "n"
Send {%hotkey% down}

Version 2:

!^z::
    hotkey := "n"
    Send {%hotkey% down}
return

Make sure that n is enclosed in "". Enclosing any text with "" means that you are assigning it as a text string. And variable used in a Send command should contain a text string.

vasili111
  • 6,032
  • 10
  • 50
  • 80
  • Nope this doesnt work. I have replied on ahkscript also http://ahkscript.org/boards/viewtopic.php?f=5&t=5105 – Paul Chambers Nov 08 '14 at 18:13
  • @PaulChambers Check **Version 2** in notepad. Hotkey is CTRL+ALT+z . Does it works in notepad? For me both versions are working. I think you are having problem with application where you use that script, not with script itself. – vasili111 Nov 08 '14 at 18:25
  • @PaulChambers I think that your problem is related with this: http://ahkscript.org/docs/commands/Send.htm#Repeating__or_Holding_Down_a_Key – vasili111 Nov 08 '14 at 18:32
  • How send as key, not text? – nim Feb 01 '19 at 00:20
  • @nim Send command sends simulated keystrokes and mouse clicks to the active window. It does not send text by itself. More about Send command here: https://autohotkey.com/docs/commands/Send.htm – vasili111 Feb 01 '19 at 02:57
0

This works in AutoHotKey V2:

key := "a"

downtext := "{" . key . " down}"
uptext := "{" . key . " up}"

Send downtext ;sends key down
Send uptext ;sends key up
alea
  • 980
  • 1
  • 13
  • 18