我正在尝试制作一个程序,当我按下热键时,它将某个文本连接到窗口中的选定文本。例如:我有文本“捕获用鼠标选择的文本”,我用鼠标选择了“文本”这个词,现在当我按下某个热键时,它会将我复制到剪贴板以下内容:xxx+text+xxx。所以我的问题是如何返回鼠标选择的单词?
谢谢!!
从你告诉我的情况来看,我理解了这一点:
unit Unit4;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, Clipbrd;
type
TForm4 = class(TForm)
procedure FormCreate(Sender: TObject);
procedure WMHotkey(var Message: TWMHotKey); message WM_HOTKEY;
procedure FormDestroy(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form4: TForm4;
implementation
const
MY_ID = 123;
{$R *.dfm}
procedure TForm4.FormCreate(Sender: TObject);
begin
RegisterHotKey(Handle, MY_ID, MOD_CONTROL, ord('1'));
end;
procedure TForm4.FormDestroy(Sender: TObject);
begin
UnregisterHotKey(Handle, MY_ID);
end;
procedure TForm4.WMHotkey(var Message: TWMHotKey);
lookup_word: string;
begin
clipboard.clear;
if Message.HotKey = MY_ID then
begin
if not AttachThreadInput(GetCurrentThreadId, GetWindowThreadProcessId(GetForegroundWindow), true) then
RaiseLastOSError;
try
SendMessage( GetFocus, WM_GETTEXT, 0, 0 );
lookup_word:= clipboard.astext;
edit1.Text := lookup_word;
Clipboard.AsText := '<font color=blue> edit1.text </font>';
SendMessage(GetFocus, WM_PASTE, 0, 0);
finally
AttachThreadInput(GetCurrentThreadId, GetWindowThreadProcessId(GetForegroundWindow), false);
end;
end;
end;
end;
end.
这个可以吗?
我设法按照我想要的方式创建我的应用程序。但我现在遇到了另一个问题。它不适用于 aspx 应用程序。它不会识别来自 aspx 编辑框的文本。有没有办法解决这个问题?
谢谢!