在AHK脚本中使用热键

时间:2018-08-25 06:22:44

标签: autohotkey

我正在尝试编写脚本来帮助我使用一些基本的C ++

Fire        UMETA(DisplayName = "Fire"),

我希望脚本键入文本的后半部分,按Home键,选择单词,复制​​它,按end键,向左移动3次并粘贴。

由于某种原因,我无法使它进行复制粘贴。我尝试添加一个延迟,以查看是否有帮助,但没有成功。我想念什么吗?

#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

1 个答案:

答案 0 :(得分:1)

尝试

^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