0

是否可以使用 AutoHotKey 将剪贴板的不同副本分配给不同的键?例如,我想复制一个数字,将其分配给 F11 键,所以当我按 F11 时,它会打印该数字。但后来我想复制一个不同的号码,并将该号码分配给 F12。是否有可能做到这一点?我知道我可以通过编辑脚本将一个数字分配给一个键,但是我分配给这些键的数字正在迅速变化,因此每次更改脚本的效率都不是很高。我认为这是不可能的,但我不妨问问。我是 AutoHotKey 和脚本的新手。这是我目前正在使用的代码:

#NoEnv ; Recommended for performance and compatibility with future AutoHotkey releases.
; #Warn ; Enable warnings to assist with detecting common errors.
SendMode Input ; Recommended for new scripts due to its superior speed and reliability.
SetWorkingDir %A_ScriptDir% ; Ensures a consistent starting directory.
~F11::
clipboard = %clipboard%
send %clipboard%
4

1 回答 1

0

有几种选择:

选项1。

+F11::  ; [Shift]+[F11] = ADD data to clipboard SHORT VERSION
    ClipBoard = ; Clear ClipBoard
    Send ^c ; Copy currently highlighted data
    Sleep, 50
    F11Save = %ClipBoard% ; Store ClipBoard data in variable %F11Save%
Return

+F11::  ; [Shift]+[F11] = ADD data to clipboard LONG VERSION
    TmpCB =%ClipBoard% ; Store previous ClipBoard Data
    ClipBoard = ; Clear ClipBoard
    Send ^c ; Copy currently highlighted data
    Sleep, 50
    F11Save = %ClipBoard%
    ClipBoard = %TmpSave% ; Restore previous ClipBoard TEXT content.
Return

F11::  ; paste text only...SHORT VERSION
    Send, %F11Save%
Return

F11::  ; paste text only...LONG VERSION
    ClipBoard = %F11Save%
    Send, ^v
Return

重复其他功能键。

选项 2 使用我前段时间写的:

#SingleInstance Force
#installKeybdHook
#Persistent
; Written by Robert Ilbrink, The Netherlands
Menu, Tray, Icon , Shell32.dll, 100, 1
SetTitleMatchMode, 2
Global Nr := 1
x:=A_ScreenWidth-250
y:=A_ScreenHeight/2
; ================================== GUI ================================== 
ShowListBox:
Gui, Add, ListBox, h270 w195 vMyListBox gMyListBox, 01 %Array_1%|02 %Array_2%|03 %Array_3%|04 %Array_4%|05 %Array_5%|06 %Array_6%|07 %Array_7%|08 %Array_8%|09 %Array_9%|10 %Array_10%|11 %Array_11%|12 %Array_12%|13 %Array_13%|14 %Array_14%|15 %Array_15%|16 %Array_16%|17 %Array_17%|18 %Array_18%|19 %Array_19%|20 %Array_20%
Gui, Add, Button, x10  y275 w45 h20, Paste
Gui, Add, Button, x60  y275 w45 h20, Refresh
Gui, Add, Button, x110 y275 w45 h20, Help
Gui, Add, Button, x160 y275 w45 h20, Special
Gui, +AlwaysOnTop
WinGet, State, MinMax, 
If (State = -1)
    Return
Else
    Gui, Show, x%x% y%y%,MultiClipBoard
Exit
; ================================== SHORTCUTS ================================== 
+^1::MySend(Array_1)  ; [Shift]+[Ctrl]+1 pastes item 1
+^2::MySend(Array_2)  ; [Shift]+[Ctrl]+2 pastes item 2
+^3::MySend(Array_3)  ; [Shift]+[Ctrl]+3 pastes item 3
+^4::MySend(Array_4)  ; [Shift]+[Ctrl]+4 pastes item 4
+^5::MySend(Array_5)  ; [Shift]+[Ctrl]+5 pastes item 5
+^6::MySend(Array_6)  ; [Shift]+[Ctrl]+6 pastes item 6
+^7::MySend(Array_7)  ; [Shift]+[Ctrl]+7 pastes item 7
+^8::MySend(Array_8)  ; [Shift]+[Ctrl]+8 pastes item 8
+^9::MySend(Array_9)  ; [Shift]+[Ctrl]+9 pastes item 9
+^0::MySend(Array_10) ; [Shift]+[Ctrl]+0 pastes item 10
+^q::MySend(Array_11) ; [Shift]+[Ctrl]+q pastes item 11
+^w::MySend(Array_12) ; [Shift]+[Ctrl]+w pastes item 12
+^e::MySend(Array_13) ; [Shift]+[Ctrl]+e pastes item 13
+^r::MySend(Array_14) ; [Shift]+[Ctrl]+r pastes item 14
+^t::MySend(Array_15) ; [Shift]+[Ctrl]+t pastes item 15
+^y::MySend(Array_16) ; [Shift]+[Ctrl]+y pastes item 16
+^u::MySend(Array_17) ; [Shift]+[Ctrl]+u pastes item 17
+^i::MySend(Array_18) ; [Shift]+[Ctrl]+i pastes item 18
+^o::MySend(Array_19) ; [Shift]+[Ctrl]+o pastes item 19
+^p::MySend(Array_20) ; [Shift]+[Ctrl]+p pastes item 20
; ================================== NUMPAD SHORTCUTS ================================== 
^Numpad1::MySend(Array_1)  ; [Ctrl]+1 pastes item 1
^Numpad2::MySend(Array_2)  ; [Ctrl]+2 pastes item 2
^Numpad3::MySend(Array_3)  ; [Ctrl]+3 pastes item 13
^Numpad4::MySend(Array_4)  ; [Ctrl]+4 pastes item 4
^Numpad5::MySend(Array_5)  ; [Ctrl]+5 pastes item 5
^Numpad6::MySend(Array_6)  ; [Ctrl]+6 pastes item 6
^Numpad7::MySend(Array_7)  ; [Ctrl]+7 pastes item 7
^Numpad8::MySend(Array_8)  ; [Ctrl]+8 pastes item 8
^Numpad9::MySend(Array_9)  ; [Ctrl]+9 pastes item 9
^Numpad0::MySend(Array_10)  ; [Ctrl]+0 pastes item 10
+^Numpad1::MySend(Array_11)  ; [Shift]+[Ctrl]+1 pastes item 11
+^Numpad2::MySend(Array_12)  ; [Shift]+[Ctrl]+2 pastes item 12
+^Numpad3::MySend(Array_13)  ; [Shift]+[Ctrl]+3 pastes item 13
+^Numpad4::MySend(Array_14)  ; [Shift]+[Ctrl]+4 pastes item 14
+^Numpad5::MySend(Array_15)  ; [Shift]+[Ctrl]+5 pastes item 15
+^Numpad6::MySend(Array_16)  ; [Shift]+[Ctrl]+6 pastes item 16
+^Numpad7::MySend(Array_17)  ; [Shift]+[Ctrl]+7 pastes item 17
+^Numpad8::MySend(Array_18)  ; [Shift]+[Ctrl]+8 pastes item 18
+^Numpad9::MySend(Array_19)  ; [Shift]+[Ctrl]+9 pastes item 19
+^Numpad0::MySend(Array_20)  ; [Shift]+[Ctrl]+0 pastes item 20
; ================================== SEND FUNCTION ================================== 
MySend(Item)
{
    ClipBoard = %Item%
    IfWinActive, MultiClipBoard
        Send, !{Esc}
    Sleep, 100
    Send, ^v
}
; ================================== SINGLE or DOUBLE CLICK ================================== 
MyListBox: ; Single Click (Normal) or Double Click (DoubleClick) to paste data back to other application
if A_GuiControlEvent <> Normal ; Alternatively use "DoubleClick"
    return
GuiControlGet, MyListBox  ; Retrieve the ListBox's current MultiClipBoard.
StringTrimLeft, ClipBoard, MyListBox, 3 
Send, !{Esc}
Sleep, 200
Send, ^v
;Send, {Enter}
;SendInput, %MyListBox%{Tab}
return
; ================================== PASTE BUTTON ================================== 
ButtonPaste: ; Select an item with [Up] / [Down] arrows and press [Paste] to paste data back to other application
Gui, Submit, NoHide
StringTrimLeft, ClipBoard, MyListBox, 3 
Send, !{Esc}
Sleep, 200
Send, ^v
;SendInput, %MyListBox%{Tab}
Return
; ================================== EXIT / CLOSE BUTTONS ================================== 
GuiClose:
GuiEscape:
Gui, Destroy
ExitApp
; ================================== REFRESH BUTTON ================================== 
ButtonRefresh:
Gui,+LastFound
WinGetPos,x,y,w,h
Gui, Destroy
GoSub, ShowListBox
Return
; ================================== Copy Into the List ================================== 
Browser_Favorites:: ; [Star] key to copy to clipboard.
!c:: ; [Alt]+c to copy to multiClipboard.
#c:: ; [Win]+c to copy to multiClipboard.
Send, ^c
Sleep, 100
Array_%Nr% := ClipBoard
Nr++
If (Nr >20) ; wrap around after 20 entries
    Nr:=1
WinGet, State, MinMax, MultiClipBoard
If (State = -1)
    Return ; GUI, Show
Gui,+LastFound
WinGetPos,x,y,w,h
Gui, Destroy
GoSub, ShowListBox
Return
; ================================== CLEAR / OPEN / SAVE ================================== 
ButtonSpecial:
SetTimer, ChangeButtonNames, 30 
MsgBox, 4098, Special Action, [Clear]`, Clears all items`n[Upload]`, Upload a txt file`n[Save]`, Save current list.
IfMsgBox, Abort ;  ================================== CLEAR ================================== 
{
    MsgBox, 4100,, Are you sure to clear the list?
    IfMsgBox No
        Return
    Nr := 1
    Loop, 20
    {
        Array_%Nr% = 
        Nr++
    }
    Nr := 1
    Gui,+LastFound
    WinGetPos,x,y,w,h
    Gui, Destroy
    GoSub, ShowListBox
    Exit
}
Else ifMsgBox, Retry ;  ================================== OPEN ================================== 
{
    FileSelectFile, SelectedFile, 3, , Open a file, Text Documents (*.txt)
    If SelectedFile =
        Exit
    Else
    {
        Loop, read, %SelectedFile%
        {
            If A_LoopReadLine =
                Break
            Array_%A_Index% := A_LoopReadLine
            If (A_Index > 20)
                Break
            Nr := A_Index + 1
        }
    }
    
    Gui,+LastFound
    WinGetPos,x,y,w,h
    Gui, Destroy
    GoSub, ShowListBox
    Exit
}
Else ifMsgBox, Ignore ;  ================================== SAVE ================================== 
{
        FileSelectFile, SelectedFile, S, , Save the list as a Text Document, (*.txt)
        StringReplace, SelectedFile, SelectedFile, `.txt, 
        FileDelete, %SelectedFile%.txt
        Loop, 20
        {
            CurrentLine := Array_%A_Index%
            FileAppend, %CurrentLine%`n, %SelectedFile%.txt ; % Array_%A_Index%, doesn't work
        }
}
Exit
; ================================== HELP BUTTON ================================== 
ButtonHelp:
MsgBox, , MultiClipBoard Help, Press [Alt]+c or [Win]+c to copy highlighted data onto the clipboard (TEXT only).`n`nClick on an item to paste it to the last active application.`n`nPress [Refresh] to refresh the screen after items were added while minimized.`n`nPress [Special] to select`n[Clear] to clear the list (after confirmation),`n[Load] to load items from a file or`n[Save] to save current items to a file. `n`n[Shift]+[Ctrl]+[nr] (1...0) will paste item 1...10.`n[Shift]+[Ctrl]+[letter] (qwertyuiop) will paste item 11...20.
; ================================== RENAME STANDARD MSGBOX BUTTONS FOR SPECIAL MENU ================================== 
ChangeButtonNames: 
IfWinNotExist, Special Action
    return  ; Keep trying.
SetTimer, ChangeButtonNames, off 
WinActivate 
ControlSetText, Button1, &Clear 
ControlSetText, Button2, &Open
ControlSetText, Button3, &Save 
return
; ================================== END ================================== 

这将显示一个小窗口,您可以在其中存储(win+c 或Alt+c)最多 20 个项目。当您单击列表中的一项时,它将被发送到打开的应用程序。

我添加了使用Shift++或数字Ctrl下方Nr的字母发送存储数据的功能。

于 2013-04-02T18:56:14.237 回答