方法一
procedure hotykey(var msg:TMessage); message WM_HOTKEY;
var
F1_ID,F2_ID,F3_ID,F4_ID,F5_ID,F6_ID,F7_ID,F8_ID,F9_ID,F10_ID,F11_ID,F12_ID,DCP_Key1,DCP_Key2,DCP_Key3,DCP_KeyQ:integer; //注册全局快捷键
procedure TDcpSSC.FormCreate(Sender: TObject);
begin
if GlobalFindAtom('MyDCP_Key1HotKey') > 0 then
begin
DCP_Key1:=GlobalAddAtom('MyDCP_Key1HotKey');
RegisterHotKey(handle,DCP_Key1,MOD_CONTROL,Ord('1'));
end ;
if GlobalFindAtom('MyDCP_Key2HotKey') > 0 then
begin
DCP_Key2:=GlobalAddAtom('MyDCP_Key1HotKey');
RegisterHotKey(handle,DCP_Key2,MOD_CONTROL,Ord('2'));
end ;
if GlobalFindAtom('MyDCP_Key3HotKey') > 0 then
begin
DCP_Key3:=GlobalAddAtom('MyDCP_Key1HotKey');
RegisterHotKey(handle,DCP_Key3,MOD_CONTROL,Ord('3'));
end ;
if GlobalFindAtom('MyDCP_KeyQHotKey')> 0 then
begin
DCP_KeyQ:=GlobalAddAtom('MyDCP_KeyQHotKey');
RegisterHotkey(Handle,DCP_KeyQ,MOD_CONTROL,Ord('Q'));
end ;
end;
procedure TDcpSSC.hotykey(var msg:TMessage);
begin
if (msg.LParamLo=MOD_CONTROL) and ( msg.LParamHi =Ord('1')) then
begi
ShowMessage('哈哈,按下了CTRL+1');
end;
if (msg.LParamLo=MOD_CONTROL) and ( msg.LParamHi =Ord('2')) then
begin
ShowMessage('哈哈,按下了CTRL+2');
end;
if (msg.LParamLo=MOD_CONTROL) and ( msg.LParamHi =51) then
begin
ShowMessage('哈哈,按下了CTRL+3');
end;
if (msg.LParamLo=MOD_CONTROL) and ( msg.LParamHi =Ord('Q')) then
begin
ShowMessage('哈哈,按下了CTRL+Q');
end;
end;
procedure TDcpSSC.FormDestroy(Sender: TObject);
begin
UnRegisterHotKey(handle,DCP_Key1);
GlobalDeleteAtom(DCP_Key1);
UnRegisterHotKey(handle,DCP_Key2);
GlobalDeleteAtom(DCP_Key2);
UnRegisterHotKey(handle,DCP_Key3);
GlobalDeleteAtom(DCP_Key3);
UnRegisterHotKey(handle,DCP_KeyQ);
GlobalDeleteAtom(DCP_KeyQ);
end;
方法二
procedure WMHotKey(var Msg : TWMHotKey); message WM_HOTKEY;
if GlobalFindAtom('MyF1HotKey') = 0 then
begin
F1_ID:=GlobalAddAtom('MyF1HotKey');
RegisterHotKey(handle,F1_id,0,VK_F1);
end;
if GlobalFindAtom('MyF2HotKey') = 0 then
begin
F2_ID:=GlobalAddAtom('MyF2HotKey');
RegisterHotKey(handle,F2_id,0,VK_F2);
end;
if GlobalFindAtom('MyF3HotKey') = 0 then
begin
F3_ID:=GlobalAddAtom('MyF3HotKey');
RegisterHotKey(handle,F3_id,0,VK_F3);
end;
if GlobalFindAtom('MyF4HotKey') = 0 then
begin
F4_ID:=GlobalAddAtom('MyF4HotKey');
RegisterHotKey(handle,F4_id,0,VK_F4);
end;
if GlobalFindAtom('MyF6HotKey') = 0 then
begin
F5_ID:=GlobalAddAtom('MyF5HotKey');
RegisterHotKey(handle,F5_id,0,VK_F5);
end;
if GlobalFindAtom('MyF6HotKey') = 0 then
begin
F6_ID:=GlobalAddAtom('MyF6HotKey');
RegisterHotKey(handle,F6_id,0,VK_F6);
end;
if GlobalFindAtom('MyF7HotKey') = 0 then
begin
F7_ID:=GlobalAddAtom('MyF7HotKey');
RegisterHotKey(handle,F7_id,0,VK_F7);
end;
if GlobalFindAtom('MyF8HotKey') = 0 then
begin
F8_ID:=GlobalAddAtom('MyF8HotKey');
RegisterHotKey(handle,F8_id,0,VK_F8);
end ;
if GlobalFindAtom('MyF9HotKey') = 0 then
begin
F9_ID:=GlobalAddAtom('MyF9HotKey');
RegisterHotKey(handle,F9_id,0,VK_F9);
end;
if GlobalFindAtom('MyF10HotKey') = 0 then
begin
F10_ID:=GlobalAddAtom('MyF10HotKey');
RegisterHotKey(handle,F10_id,0,VK_F10);
end ;
if GlobalFindAtom('MyF11HotKey') = 0 then
begin
F11_ID:=GlobalAddAtom('MyF11HotKey');
RegisterHotKey(handle,F11_id,0,VK_F11);
end ;
if GlobalFindAtom('MyF12HotKey') = 0 then
begin
F12_ID:=GlobalAddAtom('MyF12HotKey');
RegisterHotKey(handle,F12_id,0,VK_F12);
end ;
procedure TDcpSSC.WMHotKey(var Msg: TWMHotKey);
begin
//ABCDEF做单获取编辑框坐标
if msg.HotKey = F1_id then
begin
ButtonAzuClick(nil);
end;
if msg.HotKey = F2_id then
begin
ButtonBzuClick(nil);
end;
if msg.HotKey = F3_id then
begin
ButtonCzuClick(nil);
end;
if msg.HotKey = F4_id then
begin
ButtonDzuClick(nil);
end;
if msg.HotKey = F5_id then
begin
ButtonEzuClick(nil);
end;
if msg.HotKey = F6_id then
begin
ButtonFzuClick(nil);
end;
//获取编辑框坐标
if msg.HotKey = F7_id then
begin
TimerXy.enabled:=true;
end;
if msg.HotKey = F8_id then
begin
TimerXy.enabled:=false;
end;
//获取按钮坐标
if msg.HotKey = F9_id then
begin
TimerbtnXy.enabled:=true;
end;
if msg.HotKey = F10_id then
begin
TimerbtnXy.enabled:=false;
end;
//点击下注按钮
if msg.HotKey = F11_id then
begin
ButtonVrSendClick(nil);
end;
//点击测试按钮
if msg.HotKey = F12_id then
begin
ButtonVrSendTestClick(nil);
end;
end;
procedure TDcpSSC.FormDestroy(Sender: TObject);
begin
UnRegisterHotKey(handle,F1_id);
GlobalDeleteAtom(F1_id);
UnRegisterHotKey(handle,F2_id);
GlobalDeleteAtom(F2_id);
UnRegisterHotKey(handle,F3_id);
GlobalDeleteAtom(F3_id);
UnRegisterHotKey(handle,F4_id);
GlobalDeleteAtom(F4_id);
UnRegisterHotKey(handle,F5_id);
GlobalDeleteAtom(F5_id);
UnRegisterHotKey(handle,F6_id);
GlobalDeleteAtom(F6_id);
UnRegisterHotKey(handle,F7_id);
GlobalDeleteAtom(F7_id);
UnRegisterHotKey(handle,F8_id);
GlobalDeleteAtom(F8_id);
UnRegisterHotKey(handle,F9_id);
GlobalDeleteAtom(F9_id);
UnRegisterHotKey(handle,F10_id);
GlobalDeleteAtom(F10_id);
UnRegisterHotKey(handle,F11_id);
GlobalDeleteAtom(F11_id);
UnRegisterHotKey(handle,F12_id);
GlobalDeleteAtom(F12_id);
end;
个要喜欢用方案二