问题描述
我正在尝试在AutoHotKey中创建一个非常基本的文本包装程序,以便在编程时使用.我使用剪贴板复制选定的文本,对其进行修改,然后将其粘贴进行工作,但是我试图避免使用剪贴板,因为它不能与我的剪贴板管理器配合使用.有谁知道如何做到这一点?
I am trying to create a pretty basic text wrapper in AutoHotKey for use when programming. I got it to work using the clipboard to copy the selected text, modify it, then paste it, but I am trying to refrain from using the clipboard since it does not work well in conjunction 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
注意:我已经看过ControlGet, text, Selected
并尝试实现它,但是它没有用(没有错误,只是没有采取任何措施).如果有人对此有解决方案,那将解决我的问题.
Note: I have seen ControlGet, text, Selected
and attempted to implement it, but it did not work (no error, just no action). If anyone has a solution to this, that would fix my issue.
推荐答案
在AutoHotkey论坛上获得Solar的资助,以提出以下解决方案
Credit to Solar on the AutoHotkey forums for proposing the following solution
此方法有点不可靠,因为它仅适用于特定的控件类型.但是,这可能是您正在寻找的解决方案,因为它根本不使用剪贴板.
This method is a bit unreliable, as it will only work for specific control types. However, it may be the solution you are looking for, as it does not use the clipboard at all.
WinActive("A") ; sets last found window
ControlGetFocus, ctrl
if (RegExMatch(ctrl, "A)Edit\d+")) ; attempt copying without clipboard
ControlGet, text, Selected,, %ctrl%
}
这是一个建议的解决方案,尝试使用ControlSend复制文本,但是在需要时退回使用剪贴板作为备份.
Here's a proposed solution which attempts to copy text with ControlSend, but falls back to using the clipboard as a backup if needed.
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
这篇关于在不使用剪贴板的情况下获取选定的文本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!