5

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?

5 Answers 5

1

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:

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

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.

1
  • 1
    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? Mar 12, 2018 at 7:21
3

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

^k::Send %clipboard%
4
  • It says that's not allowed as an output variable...
    – RCIX
    Aug 29, 2009 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.
    – user1931
    Aug 29, 2009 at 4:39
  • My mistake, i din't pay enough attention to what line it had the error on...
    – RCIX
    Aug 29, 2009 at 5:05
  • 1
    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, 2013 at 22:50
0

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,{Raw}%Clipboard%
SendInput,{Alt}{Ctrl} ;; Try to release modifier keys
return

Though sometimes the modifier keys still get stuck...

0

For me all other answers here didn't work when trying to paste on Visual Studio (it injected a dash sign after pasting). Only this worked:

SendInput, ^v

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .