J
jimsavage
Unregistered / Unconfirmed
GUEST, unregistred user!
procedure TForm1.WMHotKey(var Msg: TWMHotKey);
begin
//如果按下热键
if msg.HotKey=id_k then
keyevent('abcde');
if msg.HotKey=id_l then
keybd_event(68, 0, 0, 0);
keybd_event(68, 0, KEYEVENTF_KEYUP, 0);
end;
procedure TForm1.FormCreate(Sender: TObject);
Const
VK_k=ord('K');
VK_l=ord('L');
begin
if GlobalFindAtom('HotKey_d')=0 then
begin
//注册全局热键Ctrl+k Ctrl+l
id_k:=GlobalAddAtom('HotKey_d');
id_l:=GlobalAddAtom('HotKey_D');
RegisterHotKey(handle,id_k,mod_CONTROL,VK_k);
RegisterHotKey(handle,id_l,mod_CONTROL,VK_l);
end;
end;
procedure TForm1.FormClose(Sender: TObject; var Action: TCloseAction);
begin
UnregisterHotKey(handle,id_k);
GlobalDeleteAtom(id_k);
UnregisterHotKey(handle,id_l);
GlobalDeleteAtom(id_l);
end;
procedure Tform1.keyevent(str:string);
var
i : integer;
c : byte;
begin
keybd_event(13, MapVirtualKey(13, 0), 0, 0);
keybd_event(13, MapVirtualKey(13, 0), KEYEVENTF_KEYUP, 0);
for i := 1 to Length(str) do
begin
c := VkKeyScan(str) and 255; //输入文字
keybd_event(c,0,0,0);
keybd_event(c,0,KEYEVENTF_KEYUP,0);
end;
keybd_event(13, MapVirtualKey(13, 0), 0, 0);
keybd_event(13, MapVirtualKey(13, 0), KEYEVENTF_KEYUP, 0);
end;
end.
begin
//如果按下热键
if msg.HotKey=id_k then
keyevent('abcde');
if msg.HotKey=id_l then
keybd_event(68, 0, 0, 0);
keybd_event(68, 0, KEYEVENTF_KEYUP, 0);
end;
procedure TForm1.FormCreate(Sender: TObject);
Const
VK_k=ord('K');
VK_l=ord('L');
begin
if GlobalFindAtom('HotKey_d')=0 then
begin
//注册全局热键Ctrl+k Ctrl+l
id_k:=GlobalAddAtom('HotKey_d');
id_l:=GlobalAddAtom('HotKey_D');
RegisterHotKey(handle,id_k,mod_CONTROL,VK_k);
RegisterHotKey(handle,id_l,mod_CONTROL,VK_l);
end;
end;
procedure TForm1.FormClose(Sender: TObject; var Action: TCloseAction);
begin
UnregisterHotKey(handle,id_k);
GlobalDeleteAtom(id_k);
UnregisterHotKey(handle,id_l);
GlobalDeleteAtom(id_l);
end;
procedure Tform1.keyevent(str:string);
var
i : integer;
c : byte;
begin
keybd_event(13, MapVirtualKey(13, 0), 0, 0);
keybd_event(13, MapVirtualKey(13, 0), KEYEVENTF_KEYUP, 0);
for i := 1 to Length(str) do
begin
c := VkKeyScan(str) and 255; //输入文字
keybd_event(c,0,0,0);
keybd_event(c,0,KEYEVENTF_KEYUP,0);
end;
keybd_event(13, MapVirtualKey(13, 0), 0, 0);
keybd_event(13, MapVirtualKey(13, 0), KEYEVENTF_KEYUP, 0);
end;
end.