如何定义程序的系统热键(100分)

  • 主题发起人 主题发起人 studydelphi999
  • 开始时间 开始时间
S

studydelphi999

Unregistered / Unconfirmed
GUEST, unregistred user!
如何定义所写程序的热键,如在我的程序中当我按下F1或F2时,就调用我所写的特定<br>程序代码,望各位高手赐教
 
创建<br>&nbsp; HotkeyId:=GlobalAddAtom(Pchar('UserDefineHotKey'))-$C000; //减去$C000是为了保证取值范围的限制<br>&nbsp; RegisterHotkey(Handle,Hotkeyid,MOD_CONTROL or MOD_Alt, $41);//敏感键为ctrl+Alt+A<br>释放<br>&nbsp; UnRegisterhotkey(Handle,HotkeyId);<br>&nbsp; DeleteAtom(HotKeyID);<br>
 
To:yzhshi<br>&nbsp; 能否给一个具体的例子,是否在工程文件中加入所写代码,我想定义为F1键,谢谢,
 
F1,好,稍等。其实你在KeyDown里面获得扫描码就OK了。[:(]
 
&nbsp;private<br>&nbsp; &nbsp; { Private declarations }<br>&nbsp; &nbsp; procedure WMHotkeyHandle(var Msg: TMessage); message WM_HOTKEY; //响应敏感键按键消息<br><br>var<br>&nbsp; HotkeyId: THandle;<br><br>procedure TForm1.WMHotkeyHandle(var Msg: TMessage);<br>begin<br>&nbsp; if (Msg.LParamHi = $70) and (msg.lparamLo = 0) then<br>&nbsp; begin<br>&nbsp; &nbsp; Msg.Result := 1; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;//该消息已经处理<br>&nbsp; &nbsp; ShowMessage('');<br>&nbsp; end;<br>end;<br><br>procedure TForm1.FormCreate(Sender: TObject);<br>begin<br>&nbsp; HotkeyId := GlobalAddAtom(Pchar('UserDefineHotKey')) - $C000;<br>&nbsp; RegisterHotkey(Handle, Hotkeyid, 0, $70);<br>end;<br><br>procedure TForm1.FormClose(Sender: TObject; var Action: TCloseAction);<br>begin<br>&nbsp; UnRegisterhotkey(Handle, HotkeyId);<br>&nbsp; DeleteAtom(HotKeyID);<br>end;<br>
 
To:yzhshi<br>我以下程序得到成功,可是我是不是要在每一个Form中都要写代码,<br>我想用你刚才的说的API,那样就不用在程序中每个Form都写同样的代码了<br>procedure TForm1.FormKeyDown(Sender: TObject; var Key: Word;<br>&nbsp; Shift: TShiftState);<br>begin<br>&nbsp; showmessage(inttostr(key));<br>end;<br>
 
看来你还没有看到我上面的代码。<br>我上上面说的是如何获得类似$41的F1的扫描码,那个扫描码可以想你这样显示出来,<br>然后修改我最初给你的两句话就OK了。<br>这个扫描码是127,即:$71,所以就出来了我编的那段程序
 
TO:yzhshi<br>谢谢,万分感谢,积分有限,献上100分,<br>我的Email是wwwwanxf@163.com,希望成为朋友
 
来这里了,本来就是朋友。[:)]
 
后退
顶部