Get selected text without using clipboard

I am trying to create a fairly simple text wrapper in AutoHotKey for use in programming. I got it to work with the clipboard, to copy the selected text, change it, and then paste it, but I try to refrain from using the clipboard, since it does not work well with my clipboard manager. Does anyone know how to do this?

!r:: ;Alt+R+%Char% = Wrap Text with Input Characters
    ClipSave := ClipboardAll
    Send ^c
    Input, Char, L1
    if ("" . Char = "{")
    {
        clipboard = {%clipboard%}
    }
    else if ("" . Char = "[")
    {
        clipboard = [%clipboard%]
    }
    else if ("" . Char = "(")
    {
        clipboard = (%clipboard%)
    }
    else
    {
        clipboard = %Char%%clipboard%%Char%
    }
    StringReplace, clipboard, clipboard,%A_SPACE%",", All
    Send ^v
    Clipboard := ClipSave
    ClipSave = 
return

Note. I saw ControlGet, text, Selectedand tried to implement it, but it did not work (without errors, without any action). If anyone has a solution, this will fix my problem.

+4
source share
2 answers

Solar AutoHotkey

ControlGet

, . , , .

WinActive("A")                           ; sets last found window
ControlGetFocus, ctrl
if (RegExMatch(ctrl, "A)Edit\d+"))       ; attempt copying without clipboard
    ControlGet, text, Selected,, %ctrl%
}

, ControlSend, .

WinActive("A")                           ; sets last found window
ControlGetFocus, ctrl
if (RegExMatch(ctrl, "A)Edit\d+"))       ; attempt copying without clipboard
    ControlGet, text, Selected,, %ctrl%  
else {                                   ; fallback solution
    clipboardOld := Clipboard            ; backup clipboard
    Send, ^c                             ; copy selected text to clipboard
    if (Clipboard != clipboardOld) {
        text := Clipboard                ; store selected text
        Clipboard := clipboardOld        ; restore clipboard contents
    }
}
MsgBox % text
+1

" ", , ctrl + c. $, alt + r -hotkey, .

$^c::
     ....
-1

All Articles