Copy source text segment with AutoHotkey

The following AutoHotkey script copies the source text segment into the Clipboard.

Requirement: segment must be unlocked.

 

; ------------------------
; Copy source text segment
; CTRL + SHIFT + C
; ------------------------
^+c::
    CheckKey_CONTROL_Up()
    CheckKey_SHIFT_Up()
    
    ; Select all in TARGET
    SelectAll()
    ; Copy all (text + tags) from TARGET
    Copy()
    Target := ClipboardAll    
    
    ; Copy from SOURCE to TARGET
    SendInput !{Insert}
    ; Select all + Copy text
    SelectAll()
    Copy()
    Source := Clipboard
    
    ; Restore TARGET
    length := StrLen(Target)
    if (length)
    {
        Undo()
        SendInput {Right}
    }
    ; Delete the following 2 lines (else + SendInput)
    ; if you want to insert SOURCE > TARGET
    ; whenever TARGET is empty
    else
        SendInput !{Delete}  
    
    ; Copy SOURCE text to Clipboard
    Clipboard := Source
return


Copy()
{
    clipboard = ; Empty Clipboard
    SendInput {control down}c{control up}
    ClipWait, 0
}

Paste()
{
    SendInput {control down}v{control up}
    Sleep, 200
}

SelectAll()
{
    SendInput {ctrl down}a{ctrl up}
}

Undo()
{
    SendInput {ctrl down}z{ctrl up}
}

; Check if CONTROL key is UP
CheckKey_CONTROL_Up()
{
    while GetKeyState("Control", P)
        Sleep, 20
}

; Check if SHIFT key is UP
CheckKey_SHIFT_Up()
{
    while GetKeyState("Shift", P)
        Sleep, 20
}

Parents Reply Children
No Data