怎样向一个窗体发消息(100分)

  • 主题发起人 主题发起人 lizheng
  • 开始时间 开始时间
L

lizheng

Unregistered / Unconfirmed
GUEST, unregistred user!
我想向街霸发击键消息,我在街霸中摄的键是W上A左S下D右J拳,我想用sendmessage,<br>但怎么也无法成功,键是发过去了,但好像不对,发键盘上任意键,游戏总是收到一组键,<br>游戏中的人物总是先发一记轻拳,在向屏幕右面两下.请各位打下帮忙看看!!!
 
让俺瞧瞧你是咋发送的?<br>俺没有街霸哟。
 
自定义消息类型。<br>接管消息事件。<br>接收判断消息类型。<br>处理事件。<br>OK!
 
SendMessage 你是怎么用的。里面的参数你写对了吗?
 
procedure TForm1.FormKeyDown(Sender: TObject; var Key: Word;<br>&nbsp; Shift: TShiftState);<br>var<br>&nbsp; H: hWnd;<br>&nbsp; vKey: byte;<br>begin<br>&nbsp; H := FindWindow('Callus95', 'Callus95 - Street Fighter II Turbo');<br>&nbsp; if SetForegroundWindow(H) then &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;//bring it to front<br>&nbsp; begin<br>&nbsp; &nbsp; vKey := Lo(Key);<br>&nbsp; &nbsp; SendMessage(H, WM_KEYDOWN, MapVirtualKey(vKey, 0), vKey);<br>&nbsp; &nbsp; Sleep(1000);<br>&nbsp; &nbsp; SendMessage(H, WM_KEYUP, MapVirtualKey(vKey, 0), vKey);<br>&nbsp; end;<br>end;
 
在FormKeyDown中写当焦点不在程序上就不能执行了。用SendMessage也不行,有个方法是注册全局热键,以下这个方法<br>我在真侍魂中试过,街霸中应该可以:<br>unit Unit1;<br><br>interface<br><br>uses<br>&nbsp; Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,<br>&nbsp; StdCtrls, Menus;<br><br>type<br>&nbsp; TForm1 = class(TForm)<br>&nbsp; &nbsp; Label1: TLabel;<br>&nbsp; &nbsp; MainMenu1: TMainMenu;<br>&nbsp; &nbsp; N1: TMenuItem;<br>&nbsp; &nbsp; procedure FormCreate(Sender: TObject);<br>&nbsp; &nbsp; procedure FormShortCut(var Msg: TWMKey; var Handled: Boolean);<br>&nbsp; &nbsp; procedure FormClose(Sender: TObject; var Action: TCloseAction);<br>&nbsp; private<br>&nbsp; &nbsp; { Private declarations }<br>&nbsp; &nbsp; HotKeyId: Integer;<br>&nbsp; &nbsp; procedure HotKeyDown(var Msg: Tmessage); message WM_HOTKEY; <br>&nbsp; public<br>&nbsp; &nbsp; { Public declarations }<br>&nbsp; end;<br><br>var<br>&nbsp; Form1: TForm1;<br><br>implementation<br><br>{$R *.DFM}<br><br>procedure TForm1.FormCreate(Sender: TObject);<br>begin<br>&nbsp; HotKeyId := GlobalAddAtom('MyHotKey') - $C000;<br>&nbsp; RegisterHotKey(Handle, hotkeyid, 0, 96);<br>end;<br><br>procedure TForm1.FormShortCut(var Msg: TWMKey; var Handled: Boolean);<br>begin<br>// &nbsp;if msg.CharCode = 13 then<br>end;<br><br>procedure TForm1.HotKeyDown(var Msg: Tmessage);<br>begin<br>&nbsp; if Msg.LParamHi = 96 then <br>&nbsp; begin<br>&nbsp; &nbsp; {<br>&nbsp; &nbsp; //奥义旋风烈斩:↓?→·斩<br>&nbsp; &nbsp; KeyBd_Event(VK_Down, MapVirtualKey(Vk_Down, 0), 0, 0);<br>&nbsp; &nbsp; Sleep(10);<br>&nbsp; &nbsp; KeyBd_Event(VK_Left, MapVirtualKey(Vk_Left, 0), 0, 0);<br>&nbsp; &nbsp; Sleep(10);<br>&nbsp; &nbsp; KeyBd_Event(VK_Down, MapVirtualKey(Vk_Down, 0), KEYEVENTF_KEYUP, 0);<br>&nbsp; &nbsp; Sleep(10);<br>&nbsp; &nbsp; KeyBd_Event(99, MapVirtualKey(99, 0), 0, 0);<br>&nbsp; &nbsp; Sleep(10);<br>&nbsp; &nbsp; KeyBd_Event(VK_Left, MapVirtualKey(Vk_Left, 0), KEYEVENTF_KEYUP, 0);<br>&nbsp; &nbsp; Sleep(10);<br>&nbsp; &nbsp; KeyBd_Event(99, MapVirtualKey(99, 0), KEYEVENTF_KEYUP, 0);}<br>&nbsp; &nbsp; <br>&nbsp; &nbsp; //奥义弧月斩:→?↓?←?·斩<br>&nbsp; &nbsp; KeyBd_Event(VK_Left, MapVirtualKey(Vk_Left, 0), 0, 0);<br>&nbsp; &nbsp; Sleep(10);<br>&nbsp; &nbsp; KeyBd_Event(VK_Down, MapVirtualKey(Vk_Down, 0), 0, 0);<br>&nbsp; &nbsp; Sleep(5);<br>&nbsp; &nbsp; KeyBd_Event(VK_Left, MapVirtualKey(VK_Left, 0), KEYEVENTF_KEYUP, 0);<br>&nbsp; &nbsp; Sleep(5);<br>&nbsp; &nbsp; KeyBd_Event(VK_Left, MapVirtualKey(Vk_Left, 0), 0, 0);<br>&nbsp; &nbsp; Sleep(5);<br>&nbsp; &nbsp; KeyBd_Event(VK_Down, MapVirtualKey(VK_Down, 0), KEYEVENTF_KEYUP, 0);<br>&nbsp; &nbsp; Sleep(5);<br>&nbsp; &nbsp; KeyBd_Event(99, MapVirtualKey(99, 0), 0, 0);<br>&nbsp; &nbsp; Sleep(5);<br>&nbsp; &nbsp; KeyBd_Event(VK_Left, MapVirtualKey(Vk_Left, 0), KEYEVENTF_KEYUP, 0);<br>&nbsp; &nbsp; Sleep(5);<br>&nbsp; &nbsp; KeyBd_Event(99, MapVirtualKey(99, 0), KEYEVENTF_KEYUP, 0);<br>&nbsp; &nbsp; {<br>&nbsp; &nbsp; //秘奥义忍法影舞:→←→←→←↓·中斩+轻踢+中踢<br>&nbsp; &nbsp; KeyBd_Event(VK_Left, MapVirtualKey(Vk_Left, 0), 0, 0);<br>&nbsp; &nbsp; Sleep(10);<br>&nbsp; &nbsp; KeyBd_Event(VK_Right, MapVirtualKey(Vk_Right, 0), 0, 0);<br>&nbsp; &nbsp; Sleep(5);<br>&nbsp; &nbsp; KeyBd_Event(VK_Left, MapVirtualKey(Vk_Left, 0), KEYEVENTF_KEYUP, 0);<br>&nbsp; &nbsp; Sleep(5);<br>&nbsp; &nbsp; KeyBd_Event(VK_Left, MapVirtualKey(Vk_Left, 0), 0, 0);<br>&nbsp; &nbsp; Sleep(5);<br>&nbsp; &nbsp; KeyBd_Event(VK_Right, MapVirtualKey(Vk_Right, 0), KEYEVENTF_KEYUP, 0);<br>&nbsp; &nbsp; Sleep(5);<br>&nbsp; &nbsp; KeyBd_Event(VK_Right, MapVirtualKey(Vk_Right, 0), 0, 0);<br>&nbsp; &nbsp; Sleep(5);<br>&nbsp; &nbsp; KeyBd_Event(VK_Left, MapVirtualKey(Vk_Left, 0), KEYEVENTF_KEYUP, 0);<br>&nbsp; &nbsp; Sleep(5);<br>&nbsp; &nbsp; KeyBd_Event(VK_Left, MapVirtualKey(Vk_Left, 0), 0, 0);<br>&nbsp; &nbsp; Sleep(5);<br>&nbsp; &nbsp; KeyBd_Event(VK_Right, MapVirtualKey(Vk_Right, 0), KEYEVENTF_KEYUP, 0);<br>&nbsp; &nbsp; Sleep(5);<br>&nbsp; &nbsp; KeyBd_Event(VK_Right, MapVirtualKey(Vk_Right, 0), 0, 0);<br>&nbsp; &nbsp; Sleep(5);<br>&nbsp; &nbsp; KeyBd_Event(VK_Left, MapVirtualKey(Vk_Left, 0), KEYEVENTF_KEYUP, 0);<br>&nbsp; &nbsp; Sleep(5);<br>&nbsp; &nbsp; KeyBd_Event(VK_Down, MapVirtualKey(Vk_Down, 0), 0, 0);<br>&nbsp; &nbsp; Sleep(5);<br>&nbsp; &nbsp; KeyBd_Event(VK_Right, MapVirtualKey(Vk_Right, 0), KEYEVENTF_KEYUP, 0);<br>&nbsp; &nbsp; Sleep(5);<br>&nbsp; &nbsp; KeyBd_Event(98, MapVirtualKey(98, 0), 0, 0);<br>&nbsp; &nbsp; KeyBd_Event(100, MapVirtualKey(100, 0), 0, 0);<br>&nbsp; &nbsp; KeyBd_Event(101, MapVirtualKey(101, 0), 0, 0);<br>&nbsp; &nbsp; Sleep(5);<br>&nbsp; &nbsp; KeyBd_Event(VK_Down, MapVirtualKey(Vk_Down, 0), KEYEVENTF_KEYUP, 0);<br>&nbsp; &nbsp; Sleep(5);<br>&nbsp; &nbsp; KeyBd_Event(98, MapVirtualKey(98, 0), KEYEVENTF_KEYUP, 0);<br>&nbsp; &nbsp; KeyBd_Event(100, MapVirtualKey(100, 0), KEYEVENTF_KEYUP, 0);<br>&nbsp; &nbsp; KeyBd_Event(101, MapVirtualKey(101, 0), KEYEVENTF_KEYUP, 0);}<br>&nbsp; end;<br>end;<br><br>procedure TForm1.FormClose(Sender: TObject; var Action: TCloseAction);<br>begin<br>&nbsp; UnRegisterHotKey(handle, HotKeyId);<br>end;<br><br>end.
 
多人接受答案了。
 
后退
顶部