I'm making an autohotkey script to run highlighted text through a calculator, and i need to send the contents of the clipboard as a sequence of keypresses, since the calculator doesn't really support pasting of a mathematical operation. How would this be accomplished?


I fixed the original script you wrote here: https://superuser.com/questions/7271/most-useful-autohotkey-scripts/31282#31282 Works fine on my Vista system now.

The code snippet in question, dredged up from the depths of the Wayback Machine:

ClipSave := ClipboardAll
Send ^x
Run calc.exe
WinWaitActive Calculator
Send ^v
Send {Enter}
Sleep 250
Send ^c
Send ^v
Clipboard := ClipSave

You need to use a command like this to "type" exactly what's in the clipboard.

^+v::SendRaw %clipboard%

^+v means ctrl+shift+v. Replace with desired keyboard shortcut. See this page for which characters map to which modifier keys.

  • If you release CTRL and SHIFT while AHK is still sending keys, the {up} event might not fire, and you're stuck with pressed SHIFT and CTRL until you press them again. What would be the most elegant way to prevent that? – Ben Philipp Mar 12 '18 at 7:21

To map Ctrl + K to send clipboard data for example:

^k::Send %clipboard%
  • It says that's not allowed as an output variable... – RCIX Aug 29 '09 at 4:22
  • what says that, the script? The script works for me I compiled and tested before posting. It should send the keys just as if it was keyboard input. – John T Aug 29 '09 at 4:39
  • My mistake, i din't pay enough attention to what line it had the error on... – RCIX Aug 29 '09 at 5:05
  • This won't include everything. The Send command tries to interpret certain characters, and they will be modified or excluded from the output (example: + and !). – Ross Jun 30 '13 at 22:50

Sending ctrl-v might work, presuming that your app actually uses that to paste, but many do not.

Another option, similar to the Send options above, but without the slowness of SendRaw and without the interpretation of Send (and with some improvement over the stuck modifier keys problem) is:

;; Alt-Control v
SendInput,{Alt}{Ctrl} ;; Try to release modifier keys

Though sometimes the modifier keys still get stuck...

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Not the answer you're looking for? Browse other questions tagged or ask your own question.