如何使程序在窗口非激活状态下按收按键响应? (200分)

  • 主题发起人 主题发起人 ameng01
  • 开始时间 开始时间
A

ameng01

Unregistered / Unconfirmed
GUEST, unregistred user!
就像ReadBook那样<br><br>ameng01@ameng.com
 
HotKey,qq不就是Alt+Ctrl+Z &nbsp;什么的,你注册就行啦。
 
具体是怎么做呢?
 
SendMessage
 
等答案.....
 
註冊熱鍵,鍵盤鈎子。留下箱子吧,我給你代碼。
 
以下是注册系统全局热键的例子,以及注册全局原子表的例子!<br><br>procedure TForm1.FormCreate(Sender: TObject);<br>Var TmpID:Integer;<br>begin<br>&nbsp; TmpID:=GlobalFindAtom('MyHotkey');<br>&nbsp; if TmpID=0 then //查找全局原子.如果返回值不为0,则说明这个全局原子已经被注册;<br>&nbsp; &nbsp; id:=GlobalAddAtom('MyHotkey')<br>&nbsp; else<br>&nbsp; &nbsp; ID:=TmpID;<br><br>&nbsp; TmpID:=GlobalFindAtom('MyHotkey1');<br>&nbsp; if TmpID=0 then<br>&nbsp; &nbsp; id1:=GlobalAddAtom('MyHotkey1')<br>&nbsp; else<br>&nbsp; &nbsp; id1:=TmpID;<br><br>&nbsp; TmpID:=GlobalFindAtom('MyHotkey2');<br>&nbsp; if TmpID=0 then<br>&nbsp; &nbsp; id2:=GlobalAddAtom('MyHotkey2')<br>&nbsp; else<br>&nbsp; &nbsp; id2:=TmpID;<br>&nbsp; RegisterHotKey(Handle, id, MOD_CONTROL, VK_F1); //注册热键:Ctrl+F1<br>&nbsp; RegisterHotKey(Handle, id1, MOD_CONTROL, VK_F2);//注册热键:Ctrl+F2<br>&nbsp; RegisterHotKey(Handle, id2, MOD_CONTROL, VK_F3);//注册热键:Ctrl+F3<br>end;<br><br>procedure TForm1.FormDestroy(Sender: TObject);<br>begin<br>&nbsp; UnregisterHotKey(Handle,ID);//释放热键Ctrl+F1<br>&nbsp; UnregisterHotKey(Handle,ID1);//释放热键Ctrl+F2<br>&nbsp; UnregisterHotKey(Handle,ID2);//释放热键Ctrl+F3<br>&nbsp; GlobalDeleteAtom(ID); //删除全局原子ID<br>&nbsp; GlobalDeleteAtom(ID1);//删除全局原子ID1<br>&nbsp; GlobalDeleteAtom(ID2);//删除全局原子ID2<br>end;<br><br>procedure TForm1.WMHotKey(var Msg: TWMHotKey);<br>begin<br>&nbsp; if msg.HotKey=ID then //热键Ctrl+F1的消息.<br>&nbsp; &nbsp; ShowMessage('Ctrl+F1!')<br>&nbsp; else if Msg.HotKey=ID1 then //热键Ctrl+F2的消息.<br>&nbsp; &nbsp; ShowMessage('Ctrl+F2!')<br>&nbsp; else if Msg.HotKey=ID2 then //热键Ctrl+F3的消息.<br>&nbsp; &nbsp; ShowMessage('Ctrl+F3!');<br>end;<br><br><br>
 
后退
顶部