第一步:注册热键const StartHotKeyID = $BF00; StopHotKeyID = $BF01; HotKeyList:array[0..11]of DWORD=( VK_F1,VK_F2,VK_F3,VK_F4,VK_F5,VK_F6, VK_F7,VK_F8,VK_F9,VK_F10,VK_F11,VK_F12 ); HotKeyListStr:array[0..11]of String= ( 'F1','F2','F3','F4','F5','F6', 'F7','F8','F9','F10','F11','F12' ); procedure TForm1.FormCreate(Sender: TObject);begin if not RegisterHotKey(handle,StartHotKeyID,MOD_CONTROL,HotKeyList[cbStart.ItemIndex]) then ShowMessage('注册启动热键Ctrl+'+HotKeyListStr[cbStart.ItemIndex]+'失败,程序运行后请重新设置!'); if not RegisterHotKey(handle,StopHotKeyID,MOD_CONTROL,HotKeyList[cbStop.ItemIndex]) then ShowMessage('注册停止热键Ctrl+'+HotKeyListStr[cbStop.ItemIndex]+'失败,程序运行后请重新设置!'); end;第二步:实现热键处理,你可以在此处理代码中改为RESTORE主程序窗口。 procedure WMHOTKEY( Var msg:TwmHotKey );message WM_HOTKEY;procedure TForm1.WMHOTKEY( Var msg:TwmHotKey );begin case msg.HotKey of StartHotKeyID: begin if cbinterval.ItemIndex < 10 then tmrTriger.Interval :=strtoint(cbInterval.text) else tmrTriger.Interval :=500+random(501); tmrTriger.Enabled :=True; MEMO1.Lines.Add('开始'); caption:='鼠标点击模拟器 - [模拟点击已启动]'; abfTrayIcon1.Hint:=Caption; DisplayMsg('鼠标模拟点击已启动!'); end; StopHotKeyID: begin tmrTriger.Enabled :=False; MEMO1.Lines.Add('停止'); caption:='鼠标点击模拟器 - [模拟点击已停止]'; abfTrayIcon1.Hint:=Caption; DisplayMsg('鼠标模拟点击已停止!'); end; end;end;第三步:取消注册的热键procedure TForm1.FormDestroy(Sender: TObject);begin UnregisterHotKey(handle,StartHotKeyID); UnregisterHotKey(handle,StopHotKeyID);end;