0

I'm interested in having multiple clipboards that are accessable using 3 different hotkeys.

(Ideally, (control+1), control+2, control+3 for copying, and alt+1, alt+2, and alt+3 for pasting.

First I tried using autohotkey using this code:

#Persistent

; Hotkeys
^F1::Copy(1)
^+F1::Paste(1)

^F2::Copy(2)
^+F2::Paste(2)

^F3::Copy(3)
^+F3::Paste(3)

Copy(clipboardID)
{
    global ; All variables are global by default
    local oldClipboard := ClipboardAll ; Save the (real) clipboard

    Clipboard = ; Erase the clipboard first, or else ClipWait does nothing
    Send ^c
    ClipWait, 2, 1 ; Wait 1s until the clipboard contains any kind of data
    if ErrorLevel 
    {
        Clipboard := oldClipboard ; Restore old (real) clipboard
        return
    }

    ClipboardData%clipboardID% := ClipboardAll

    Clipboard := oldClipboard ; Restore old (real) clipboard
}

Cut(clipboardID)
{
    global ; All variables are global by default
    local oldClipboard := ClipboardAll ; Save the (real) clipboard

    Clipboard = ; Erase the clipboard first, or else ClipWait does nothing
    Send ^x
    ClipWait, 2, 1 ; Wait 1s until the clipboard contains any kind of data
    if ErrorLevel 
    {
        Clipboard := oldClipboard ; Restore old (real) clipboard
        return
    }
    ClipboardData%clipboardID% := ClipboardAll

    Clipboard := oldClipboard ; Restore old (real) clipboard
}

Paste(clipboardID)
{
    global
    local oldClipboard := ClipboardAll ; Save the (real) clipboard

    Clipboard := ClipboardData%clipboardID%
    Send ^v

    Clipboard := oldClipboard ; Restore old (real) clipboard
    oldClipboard = 
}

I used those hotkeys because, like this person mentions, there's like only a few possible hotkey combinations that aren't taken by other programs.

But it's constantly breaking. It consistently forgets the new thing I save and keeps inserting what's saved via the normal clipboard command: "control+c".

Any ideas what I can do to fix this. Also I tried using "ditto" but was unsuccessful in getting it to actually register keys for multiple clipboards...

1

If a program is running with admin privileges, AHK won't intercept the key presses, and that could be the reason behind your problem.

If that is the case, try to run the AHK script as administrator by adding this to the auto-execute section (top of the script):

; If the script is not elevated, relaunch as administrator and kill current instance:

full_command_line := DllCall("GetCommandLine", "str")

if not (A_IsAdmin or RegExMatch(full_command_line, " /restart(?!\S)"))
{
    try ; leads to having the script re-launching itself as administrator
    {
        if A_IsCompiled
            Run *RunAs "%A_ScriptFullPath%" /restart
        else
            Run *RunAs "%A_AhkPath%" /restart "%A_ScriptFullPath%"
    }
    ExitApp
}

For more details read https://autohotkey.com/docs/commands/Run.htm#RunAs.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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