在FormKeyDown中写当焦点不在程序上就不能执行了。用SendMessage也不行,有个方法是注册全局热键,以下这个方法<br>我在真侍魂中试过,街霸中应该可以:<br>unit Unit1;<br><br>interface<br><br>uses<br> Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,<br> StdCtrls, Menus;<br><br>type<br> TForm1 = class(TForm)<br> Label1: TLabel;<br> MainMenu1: TMainMenu;<br> N1: TMenuItem;<br> procedure FormCreate(Sender: TObject);<br> procedure FormShortCut(var Msg: TWMKey; var Handled: Boolean);<br> procedure FormClose(Sender: TObject; var Action: TCloseAction);<br> private<br> { Private declarations }<br> HotKeyId: Integer;<br> procedure HotKeyDown(var Msg: Tmessage); message WM_HOTKEY; <br> public<br> { Public declarations }<br> end;<br><br>var<br> Form1: TForm1;<br><br>implementation<br><br>{$R *.DFM}<br><br>procedure TForm1.FormCreate(Sender: TObject);<br>begin<br> HotKeyId := GlobalAddAtom('MyHotKey') - $C000;<br> RegisterHotKey(Handle, hotkeyid, 0, 96);<br>end;<br><br>procedure TForm1.FormShortCut(var Msg: TWMKey; var Handled: Boolean);<br>begin<br>// if msg.CharCode = 13 then<br>end;<br><br>procedure TForm1.HotKeyDown(var Msg: Tmessage);<br>begin<br> if Msg.LParamHi = 96 then <br> begin<br> {<br> //奥义旋风烈斩:↓?→·斩<br> KeyBd_Event(VK_Down, MapVirtualKey(Vk_Down, 0), 0, 0);<br> Sleep(10);<br> KeyBd_Event(VK_Left, MapVirtualKey(Vk_Left, 0), 0, 0);<br> Sleep(10);<br> KeyBd_Event(VK_Down, MapVirtualKey(Vk_Down, 0), KEYEVENTF_KEYUP, 0);<br> Sleep(10);<br> KeyBd_Event(99, MapVirtualKey(99, 0), 0, 0);<br> Sleep(10);<br> KeyBd_Event(VK_Left, MapVirtualKey(Vk_Left, 0), KEYEVENTF_KEYUP, 0);<br> Sleep(10);<br> KeyBd_Event(99, MapVirtualKey(99, 0), KEYEVENTF_KEYUP, 0);}<br> <br> //奥义弧月斩:→?↓?←?·斩<br> KeyBd_Event(VK_Left, MapVirtualKey(Vk_Left, 0), 0, 0);<br> Sleep(10);<br> KeyBd_Event(VK_Down, MapVirtualKey(Vk_Down, 0), 0, 0);<br> Sleep(5);<br> KeyBd_Event(VK_Left, MapVirtualKey(VK_Left, 0), KEYEVENTF_KEYUP, 0);<br> Sleep(5);<br> KeyBd_Event(VK_Left, MapVirtualKey(Vk_Left, 0), 0, 0);<br> Sleep(5);<br> KeyBd_Event(VK_Down, MapVirtualKey(VK_Down, 0), KEYEVENTF_KEYUP, 0);<br> Sleep(5);<br> KeyBd_Event(99, MapVirtualKey(99, 0), 0, 0);<br> Sleep(5);<br> KeyBd_Event(VK_Left, MapVirtualKey(Vk_Left, 0), KEYEVENTF_KEYUP, 0);<br> Sleep(5);<br> KeyBd_Event(99, MapVirtualKey(99, 0), KEYEVENTF_KEYUP, 0);<br> {<br> //秘奥义忍法影舞:→←→←→←↓·中斩+轻踢+中踢<br> KeyBd_Event(VK_Left, MapVirtualKey(Vk_Left, 0), 0, 0);<br> Sleep(10);<br> KeyBd_Event(VK_Right, MapVirtualKey(Vk_Right, 0), 0, 0);<br> Sleep(5);<br> KeyBd_Event(VK_Left, MapVirtualKey(Vk_Left, 0), KEYEVENTF_KEYUP, 0);<br> Sleep(5);<br> KeyBd_Event(VK_Left, MapVirtualKey(Vk_Left, 0), 0, 0);<br> Sleep(5);<br> KeyBd_Event(VK_Right, MapVirtualKey(Vk_Right, 0), KEYEVENTF_KEYUP, 0);<br> Sleep(5);<br> KeyBd_Event(VK_Right, MapVirtualKey(Vk_Right, 0), 0, 0);<br> Sleep(5);<br> KeyBd_Event(VK_Left, MapVirtualKey(Vk_Left, 0), KEYEVENTF_KEYUP, 0);<br> Sleep(5);<br> KeyBd_Event(VK_Left, MapVirtualKey(Vk_Left, 0), 0, 0);<br> Sleep(5);<br> KeyBd_Event(VK_Right, MapVirtualKey(Vk_Right, 0), KEYEVENTF_KEYUP, 0);<br> Sleep(5);<br> KeyBd_Event(VK_Right, MapVirtualKey(Vk_Right, 0), 0, 0);<br> Sleep(5);<br> KeyBd_Event(VK_Left, MapVirtualKey(Vk_Left, 0), KEYEVENTF_KEYUP, 0);<br> Sleep(5);<br> KeyBd_Event(VK_Down, MapVirtualKey(Vk_Down, 0), 0, 0);<br> Sleep(5);<br> KeyBd_Event(VK_Right, MapVirtualKey(Vk_Right, 0), KEYEVENTF_KEYUP, 0);<br> Sleep(5);<br> KeyBd_Event(98, MapVirtualKey(98, 0), 0, 0);<br> KeyBd_Event(100, MapVirtualKey(100, 0), 0, 0);<br> KeyBd_Event(101, MapVirtualKey(101, 0), 0, 0);<br> Sleep(5);<br> KeyBd_Event(VK_Down, MapVirtualKey(Vk_Down, 0), KEYEVENTF_KEYUP, 0);<br> Sleep(5);<br> KeyBd_Event(98, MapVirtualKey(98, 0), KEYEVENTF_KEYUP, 0);<br> KeyBd_Event(100, MapVirtualKey(100, 0), KEYEVENTF_KEYUP, 0);<br> KeyBd_Event(101, MapVirtualKey(101, 0), KEYEVENTF_KEYUP, 0);}<br> end;<br>end;<br><br>procedure TForm1.FormClose(Sender: TObject; var Action: TCloseAction);<br>begin<br> UnRegisterHotKey(handle, HotKeyId);<br>end;<br><br>end.