Althaen
Althaen

Reputation: 47

Using hotkeys in an AHK script

I am trying to write a script to help me with some basic C++

Fire        UMETA(DisplayName = "Fire"),

I want the script to type out the second half of the text, press home, select the word, copy it, press end, left 3 times and paste.

I can't get it to do the copy pasting for some reason. I tried adding a delay to see if that helped but it doesn't. Am I missing something?

#SingleInstance force

^e::

sendinput, UMETA(DisplayName = ""),
sendinput, {home}
sendinput, {^w}
sleep, 20
sendinput, {^c}
sleep, 20
sendinput, {end}
sendinput, {left 3}
sendinput, {^v}
sleep, 20

Upvotes: 0

Views: 114

Answers (1)

Relax
Relax

Reputation: 10543

Try

^e::
    ClipSaved := ClipboardAll      ; save the entire clipboard into the variable ClipSaved
    clipboard := ""                ; empty the clipboard (start off empty to allow ClipWait to detect when the text has arrived)
    SendInput, UMETA(DisplayName = ""),
    Sleep, 30
    SendInput, {home}^+{Right}     ; select the 1st word
    Sleep, 30
    Send, ^c                       ; copy the selected text
    ClipWait, 1                    ; wait max 1 sec for the clipboard to contain data 
    if (!ErrorLevel)               ; If NOT ErrorLevel, ClipWait found data on the clipboard
    {
        clipboard := Trim(clipboard, "`r`n `t") ; trim CRs/LFs, spaces and tabs
        SendInput,{end}{left 3}^v
    }
    Sleep, 300
    clipboard := ClipSaved        ; restore original clipboard
return

Upvotes: 1

Related Questions