注册个热键可以实现你想要的功能,免去用Hook的麻烦了。但得运行你的注册热键的程序才行,<br>下面的是按F4键就运行记事本。<br> private<br> { Private declarations }<br> myHotKey: Integer;<br> procedure wmHotKey(var Msg: Tmessage); message WM_HOTKEY;<br>procedure TForm1.FormCreate(Sender: TObject);<br>begin<br> myHotKey := GlobalAddAtom('MyHotKey') - $C000;<br> RegisterHotKey(Handle, myHotkey, 0, VK_F4);<br>end;<br>procedure TForm1.wmHotKey(var Msg: Tmessage);<br>begin<br> if (Msg.LParamHi = VK_F4) then<br> begin<br> WinExec('notepad.exe', SW_Normal);<br> end;<br>end;<br>procedure TForm1.FormClose(Sender: TObject; var Action: TCloseAction);<br>begin<br> UnRegisterHotKey(handle, myHotKey);<br>end;<br>