unit Unit1;
interface
uses
Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants,
System.Classes, Vcl.Graphics, Vcl.Controls, Vcl.Forms, Vcl.Dialogs,
Vcl.StdCtrls, Vcl.ComCtrls;
type
TForm1 = class(TForm)
RichEdit1: TRichEdit;
procedure FormCreate(Sender: TObject);
procedure hotykey(var msg: TMessage); message WM_HOTKEY;
procedure FormDestroy(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
id1, id2, id3, id4: Integer; //id1 ctrl+shift+v , id2 ctrl+shift+window+v
implementation
{$R *.dfm}
procedure TForm1.FormDestroy(Sender: TObject);
begin
UnRegisterHotKey(handle, id1); //ctrl+shift+V
UnRegisterHotKey(handle, id2); //ctrl+shift+window+V
UnRegisterHotKey(handle, id3); //ctrl+shift+Alt+Window+V
UnRegisterHotKey(handle, id4); //Window+S
end;
procedure TForm1.hotykey(var msg: TMessage); //定义下面这种热键,要先写长的判断,不然没有反应!这就是原因!
begin
if (GetAsyncKeyState(VK_CONTROL) < 0) and (GetAsyncKeyState(VK_SHIFT) < 0) and (GetAsyncKeyState(VK_MENU) and (GetAsyncKeyState(VK_LWIN) and (GetAsyncKeyState(Ord('V')))) < 0) then //Ctrl+Shift+Alt+Window+V
ShowMessage('Ctrl+Shift+Alt+Window+V');
if (GetAsyncKeyState(VK_CONTROL) < 0) and (GetAsyncKeyState(VK_SHIFT) < 0) and (GetAsyncKeyState(VK_LWIN) and (GetAsyncKeyState(Ord('V'))) < 0) then //Ctrl+Shift+Window+V
ShowMessage('Ctrl+Shift+Window+V');
if (GetAsyncKeyState(VK_LWIN) and (GetAsyncKeyState(Ord('S'))) < 0) then //Window+V
ShowMessage('Window+S');
//if (msg.LParamLo = MOD_CONTROL) and (msg.LParamHi = 86) then
if (GetAsyncKeyState(VK_CONTROL) < 0) and (GetAsyncKeyState(VK_SHIFT) < 0) and (GetAsyncKeyState(Ord('V')) < 0) then //ctrl+shift+v
begin
ShowMessage('ctrl+shift+v');
RichEdit1.PasteFromClipboard;
end;
end;
procedure TForm1.FormCreate(Sender: TObject); //另外 hotkey1 hotkey2 hotkey3要写三个
begin
id1 := GlobalAddAtom('hotkey1');
RegisterHotKey(handle, id1, MOD_CONTROL + MOD_SHIFT, 86); //ctrl+shift+V 成功了~~
id2 := GlobalAddAtom('hotkey2');
RegisterHotKey(handle, id2, MOD_CONTROL + MOD_SHIFT + MOD_WIN, 86); //ctrl+shift+window+V 成功了~~
id3 := GlobalAddAtom('hotkey3');
RegisterHotKey(handle, id3, MOD_CONTROL + MOD_SHIFT + MOD_ALT + MOD_WIN, 86); //ctrl+shift+Alt+Window+V 成功了~~
id4 := GlobalAddAtom('hotkey4');
RegisterHotKey(handle, id4, MOD_WIN, 83); //Window+V
end;
end.
|