所有家当全部给你! 求用postmessage向其他程序发送快捷组合键的控件或程序。(62分)

  • 主题发起人 主题发起人 16cy
  • 开始时间 开始时间
1

16cy

Unregistered / Unconfirmed
GUEST, unregistred user!
谁有用postmessage或sendmessage向其他程序发送快捷组合键的控件或程序?<br>我全部家当只有62分了,有的话全部送给你~
 
procedure TForm1.Button1Click(Sender: TObject); <br>var <br> TEMP:HWND; <br>begin <br>TEMP:=FindWindow(nil,'Form2'); //这里写上你要查找的窗体的标题名称。当然,如果你知道了对象窗口的Handle,可以直接在下面使用。<br>if TEMP&lt;&gt; 0 then <br> SendMessage(TEMP,WM_KEYDOWN,VK_F3,0); <br>end;
 
请看清,我要的是发送快捷组合键,不是发送单纯的F3,F4之类的,而是比如<br>“CTR+F3” <br>“CTR+ALT+A”<br>之类的快捷键
 
SendMessage(TEMP,WM_KEYDOWN,VK_Control,0); <br>SendMessage(TEMP,WM_KEYDOWN,VK_F3,0); <br>Sleep(50);<br>SendMessage(TEMP,WM_KEYUP,VK_F3,0); <br>SendMessage(TEMP,WM_KEYUP,VK_Control,0);
 
to 白河愁:<br>你有没有试过啊,你这样的语句我早试过N篇了,传过去的不是快捷键。<br><br>另:你的API hook的控件例子放在哪里了?找不到啊?
 
当然试过,除非目标进程封锁了消息(比如游戏)。<br>控件就放在原来那帖里,同一个下载地址
 
刚才下载了,没有新的例子,还是原来的。<br><br>另外你的语句真的不起作用。我试过很多次的,你说游戏封锁了消息好象也不对,他能响应快键。<br><br>用你的语句的话,如果按&quot;alt+a&quot;,其结果不是快键&quot;alt+a&quot;,而是发送了乱码+字符A到游戏聊天输入窗口<br><br>SendMessage(TEMP,WM_KEYDOWN,VK_menu,0); <br>SendMessage(TEMP,WM_KEYDOWN,VK_F3,0); <br>Sleep(50);<br>SendMessage(TEMP,WM_KEYUP,VK_F3,0); <br>SendMessage(TEMP,WM_KEYUP,VK_menu,0);
 
你有没有看清楚,如果<br>http://www.ff18.com/delphi/apihooker.rar<br>还是原来的,只能说是你的 rpwt 了。<br><br>我那句是发送 ctrl +f3, 你怎么改成 alt 的 ?
 
发送Ctrl的也一样<br>另外,我再下了一遍你的API控件,还是没找到你说的例子,依然只有你的send的例子
 
shift $2000<br>ctrl $4000<br>alt $8000<br>用上面的在加上字母的值就行了<br>如ctrl + a = $4000 + $41
 
to Corinth:<br>两种方法是一样的,<br>delphi中早定义好了的,还用得着再这样吗?<br>那不是画蛇添足吗?
 
我已经下载过确认没问题的了,自己检查一下吧,相信sendmessage也是同样问题。
 
runhook里面一共有6个文件,hookdll里面一共有四个文件,bin里面一共有3个文件<br>全是以前的,哪里有新例子啊?
 
看到了,但是都没有看到你的使用你自已的控件啊,我是说要一个使用你的控件的例子。
 
做法就错误,不是发送快捷组合键消息,这样是无效的
 
to zj_mpy:那么要怎么发?
 
to 白河愁:<br>我编译了你的示例程序,只有按下ctr+H有反应。<br>按ctrl+1 ctrl+2 ctrl+3都没有任何反应,也没有任何变化,不知道是什么原因?
 
前几天帮朋友做的。。。发送组合键到游戏中<br>用到些第三方控件,可以换为对应的普通控件<br>可以全局按键操作或非全局按键操作<br><br>Unit Main;<br><br>Interface<br><br>Uses<br> &nbsp;Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,<br> &nbsp;Dialogs, StdCtrls, RzCommon, ComCtrls, RzEdit, RzTray, RzButton, RzRadChk,<br> &nbsp;RzLabel, ExtCtrls, ImgList, Inifiles, menus, Mask;<br><br>Type<br> &nbsp;TFrmMain = Class(TForm)<br> &nbsp; &nbsp;Tray: TRzTrayIcon;<br> &nbsp; &nbsp;HotKey1: TRzHotKeyEdit;<br> &nbsp; &nbsp;RzFrameController1: TRzFrameController;<br> &nbsp; &nbsp;lbl1: TLabel;<br> &nbsp; &nbsp;lbl2: TLabel;<br> &nbsp; &nbsp;HotKey2: TRzHotKeyEdit;<br> &nbsp; &nbsp;LbHwnd: TRzLabel;<br> &nbsp; &nbsp;lbl3: TLabel;<br> &nbsp; &nbsp;Timer: TTimer;<br> &nbsp; &nbsp;CmdStart: TRzBitBtn;<br> &nbsp; &nbsp;CmdStop: TRzBitBtn;<br> &nbsp; &nbsp;CmdMouse: TRzToolButton;<br> &nbsp; &nbsp;il1: TImageList;<br> &nbsp; &nbsp;Up: TRzNumericEdit;<br> &nbsp; &nbsp;lbl4: TLabel;<br> &nbsp; &nbsp;ChkGol: TRzCheckBox;<br> &nbsp; &nbsp;Procedure CmdMouseMouseDown(Sender: TObject; Button: TMouseButton;<br> &nbsp; &nbsp; &nbsp;Shift: TShiftState; X, Y: Integer);<br> &nbsp; &nbsp;Procedure CmdMouseMouseUp(Sender: TObject; Button: TMouseButton;<br> &nbsp; &nbsp; &nbsp;Shift: TShiftState; X, Y: Integer);<br> &nbsp; &nbsp;Procedure CmdMouseMouseMove(Sender: TObject; Shift: TShiftState; X,<br> &nbsp; &nbsp; &nbsp;Y: Integer);<br> &nbsp; &nbsp;Procedure FormCreate(Sender: TObject);<br> &nbsp; &nbsp;Procedure FormClose(Sender: TObject; Var Action: TCloseAction);<br> &nbsp; &nbsp;Procedure CmdStartClick(Sender: TObject);<br> &nbsp; &nbsp;Procedure CmdStopClick(Sender: TObject);<br> &nbsp; &nbsp;Procedure TimerTimer(Sender: TObject);<br> &nbsp;Private<br> &nbsp; &nbsp;Hwd: Hwnd;<br> &nbsp; &nbsp;SpyMode: Boolean;<br> &nbsp; &nbsp;P: TPoint;<br><br> &nbsp; &nbsp;HotID: Integer;<br> &nbsp; &nbsp;CurV: Integer;<br> &nbsp; &nbsp;Ini: Tinifile;<br> &nbsp; &nbsp;Procedure HotKey(Var msg: TWMHotKey); Message WM_HOTKEY;<br> &nbsp; &nbsp;Procedure LoadConfigs;<br> &nbsp; &nbsp;Procedure SaveConfigs;<br> &nbsp; &nbsp;Procedure SetControls(B: Boolean);<br> &nbsp;Public<br> &nbsp; &nbsp;{ Public declarations }<br> &nbsp;End;<br><br>Var<br> &nbsp;FrmMain: TFrmMain;<br><br>Implementation<br><br>{$R *.dfm}<br>Procedure SetUpKey(ShortCut: TShortCut; Var Modifiers, Key: Word);<br>Var<br> &nbsp;Shift: TShiftState;<br>Begin<br> &nbsp;ShortCutToKey(ShortCut, Key, Shift);<br> &nbsp;Modifiers := 0;<br> &nbsp;If ssShift In Shift Then Modifiers := Modifiers Or MOD_SHIFT;<br> &nbsp;If ssCtrl In Shift Then Modifiers := Modifiers Or MOD_CONTROL;<br> &nbsp;If ssAlt In Shift Then Modifiers := Modifiers Or MOD_ALT;<br>End;<br><br>Procedure TFrmMain.HotKey(Var msg: TWMHotKey);<br>Begin<br> &nbsp;If HotKey1.Focused Then exit;<br> &nbsp;If msg.HotKey = HotID Then<br> &nbsp; &nbsp;If CmdStop.Enabled Then<br> &nbsp; &nbsp; &nbsp;CmdStop.Click Else CmdStart.Click;<br>End;<br><br>Procedure TFrmMain.LoadConfigs;<br>Var<br> &nbsp;Modifiers, Key: Word;<br>Begin<br> &nbsp;Ini := Tinifile.Create(ExtractFilePath(ParamStr(0)) + 'Config.ini');<br> &nbsp;HotKey1.HotKey := TextToShortCut(Ini.ReadString('Config', 'AppKey', 'CTRL+F12'));<br> &nbsp;HotKey2.HotKey := TextToShortCut(Ini.ReadString('Config', 'GameKey', '无'));<br> &nbsp;Up.IntValue := Ini.ReadInteger('Config', 'DoTime', 3);<br> &nbsp;ChkGol.Checked := Ini.ReadBool('Config', 'IsGobalKey', False);<br> &nbsp;SetUpKey(HotKey1.HotKey, Modifiers, Key);<br> &nbsp;HotID := GlobalAddAtom('HotKey_AppGame');<br> &nbsp;RegisterHotKey(handle, HotID, Modifiers, Key);<br>End;<br><br>Procedure TFrmMain.SaveConfigs;<br>Begin<br> &nbsp;UnregisterHotKey(handle, HotID);<br> &nbsp;GlobalDeleteAtom(HotID);<br> &nbsp;Ini.WriteString('Config', 'AppKey', ShortCutToText(HotKey1.HotKey));<br> &nbsp;Ini.WriteString('Config', 'GameKey', ShortCutToText(HotKey2.HotKey));<br> &nbsp;Ini.WriteInteger('Config', 'DoTime', Up.IntValue);<br> &nbsp;Ini.WriteBool('Config', 'IsGobalkey', ChkGol.Checked);<br>End;<br><br>Procedure TFrmMain.SetControls(B: Boolean);<br>Begin<br> &nbsp;CmdStart.Enabled := B;<br> &nbsp;CmdStop.Enabled := Not B;<br> &nbsp;Timer.Enabled := Not B;<br> &nbsp;HotKey1.Enabled := B;<br> &nbsp;HotKey2.Enabled := B;<br> &nbsp;CmdMouse.Enabled := B;<br> &nbsp;Up.Enabled := B;<br> &nbsp;LbHwnd.Enabled := B;<br> &nbsp;ChkGol.Enabled := B;<br>End;<br><br>Procedure TFrmMain.CmdMouseMouseDown(Sender: TObject; Button: TMouseButton;<br> &nbsp;Shift: TShiftState; X, Y: Integer);<br>Begin<br> &nbsp;Screen.Cursor := crCross;<br> &nbsp;SetCapture(handle);<br> &nbsp;SpyMode := true;<br> &nbsp;SetWindowPos(handle, HWND_TOPMOST, 0, 0, 0, 0, swp_nomove Or swp_nosize);<br>End;<br><br>Procedure TFrmMain.CmdMouseMouseUp(Sender: TObject; Button: TMouseButton;<br> &nbsp;Shift: TShiftState; X, Y: Integer);<br>Begin<br> &nbsp;Screen.Cursor := crDefault;<br> &nbsp;ReleaseCapture;<br> &nbsp;SpyMode := False;<br> &nbsp;SetWindowPos(handle, HWND_NOTOPMOST, 0, 0, 0, 0, swp_nomove Or swp_nosize);<br>End;<br><br>Procedure TFrmMain.CmdMouseMouseMove(Sender: TObject; Shift: TShiftState;<br> &nbsp;X, Y: Integer);<br>Begin<br> &nbsp;If Not SpyMode Then exit;<br> &nbsp;GetCursorPos(P);<br> &nbsp;Hwd := WindowFromPoint(P);<br> &nbsp;LbHwnd.Caption := IntToStr(Hwd);<br>End;<br><br>Procedure TFrmMain.FormCreate(Sender: TObject);<br>Begin<br> &nbsp;Ini := Tinifile.Create(ExtractFilePath(ParamStr(0)) + 'Config.ini');<br> &nbsp;LoadConfigs;<br>End;<br><br>Procedure TFrmMain.FormClose(Sender: TObject; Var Action: TCloseAction);<br>Begin<br> &nbsp;CmdStop.Click;<br> &nbsp;SaveConfigs;<br> &nbsp;Ini.Free;<br>End;<br><br>Procedure TFrmMain.CmdStartClick(Sender: TObject);<br>Begin<br> &nbsp;SaveConfigs;<br> &nbsp;LoadConfigs;<br> &nbsp;If (Hwd = 0) Then<br> &nbsp;Begin<br> &nbsp; &nbsp;MessageBox(handle, '请查找准备控制的窗口句柄!', '错误', MB_ICONHAND);<br> &nbsp; &nbsp;exit;<br> &nbsp;End;<br> &nbsp;If (HotKey2.HotKey = 0) Then<br> &nbsp;Begin<br> &nbsp; &nbsp;MessageBox(handle, '请设置执行键值!', '错误', MB_ICONHAND);<br> &nbsp; &nbsp;exit;<br> &nbsp;End;<br> &nbsp;SetControls(False);<br> &nbsp;CurV := 0;<br>End;<br><br>Procedure TFrmMain.CmdStopClick(Sender: TObject);<br>Begin<br> &nbsp;SetControls(true);<br>End;<br><br>Type<br> &nbsp;TSMsg = Packed Record<br> &nbsp; &nbsp;Shift: TShiftState;<br> &nbsp; &nbsp;Key: Word;<br> &nbsp;End;<br><br>Procedure SendMsg(AhWnd: Hwnd; M: TSMsg);<br>Begin<br> &nbsp;If ssShift In M.Shift Then<br> &nbsp; &nbsp;PostMessage(AhWnd, WM_KEYDOWN, VK_SHIFT, 0);<br> &nbsp;If ssAlt In M.Shift Then<br> &nbsp; &nbsp;PostMessage(AhWnd, WM_KEYDOWN, VK_MENU, 0);<br> &nbsp;If ssCtrl In M.Shift Then<br> &nbsp; &nbsp;PostMessage(AhWnd, WM_KEYDOWN, VK_CONTROL, 0);<br><br> &nbsp;PostMessage(AhWnd, WM_KEYDOWN, M.Key, 0);<br> &nbsp;PostMessage(AhWnd, WM_KEYUP, M.Key, 0);<br><br> &nbsp;If ssShift In M.Shift Then<br> &nbsp; &nbsp;PostMessage(AhWnd, WM_KEYUP, VK_SHIFT, 0);<br> &nbsp;If ssAlt In M.Shift Then<br> &nbsp; &nbsp;PostMessage(AhWnd, WM_KEYUP, VK_MENU, 0);<br> &nbsp;If ssCtrl In M.Shift Then<br> &nbsp; &nbsp;PostMessage(AhWnd, WM_KEYUP, VK_CONTROL, 0);<br>End;<br><br>Function EnumChildWndProc(AhWnd: Hwnd; AlParam: Pointer): Boolean; Stdcall;<br>Begin//遍历窗口句柄内的所有控件并发送键消息<br> &nbsp;SendMsg(AhWnd, TSMsg(AlParam^));<br> &nbsp;result := true;<br>End;<br><br>定时发送<br>Procedure TFrmMain.TimerTimer(Sender: TObject);<br>Var<br> &nbsp;M: TSMsg;<br> &nbsp;ThreadID: DWord;<br>Begin<br> &nbsp;Inc(CurV);<br> &nbsp;If CurV = Up.IntValue Then<br> &nbsp;Begin<br> &nbsp; &nbsp;CurV := 0;<br> &nbsp; &nbsp;ShortCutToKey(HotKey2.HotKey, M.Key, M.Shift);<br> &nbsp; &nbsp;If ChkGol.Checked Then<br> &nbsp; &nbsp;Begin<br> &nbsp; &nbsp; &nbsp;ThreadID := GetWindowThreadProcessId(Hwd, Nil);<br> &nbsp; &nbsp; &nbsp;AttachThreadInput(GetCurrentThreadId, ThreadID, true);<br> &nbsp; &nbsp; &nbsp;//ShowWindow(Hwd, SW_SHOWNOACTIVATE);<br> &nbsp; &nbsp; &nbsp;SetForegroundWindow(Hwd);<br> &nbsp; &nbsp; &nbsp;If ssShift In M.Shift Then<br> &nbsp; &nbsp; &nbsp; &nbsp;keybd_event(VK_SHIFT, MapVirtualKey(VK_SHIFT, 0), 0, 0);<br> &nbsp; &nbsp; &nbsp;If ssAlt In M.Shift Then<br> &nbsp; &nbsp; &nbsp; &nbsp;keybd_event(VK_MENU, MapVirtualKey(VK_MENU, 0), 0, 0);<br> &nbsp; &nbsp; &nbsp;If ssCtrl In M.Shift Then<br> &nbsp; &nbsp; &nbsp; &nbsp;keybd_event(VK_CONTROL, MapVirtualKey(VK_CONTROL, 0), 0, 0);<br><br> &nbsp; &nbsp; &nbsp;keybd_event(M.Key, MapVirtualKey(M.Key, 0), 0, 0);<br> &nbsp; &nbsp; &nbsp;keybd_event(M.Key, MapVirtualKey(M.Key, 0), KEYEVENTF_KEYUP, 0);<br><br> &nbsp; &nbsp; &nbsp;If ssShift In M.Shift Then<br> &nbsp; &nbsp; &nbsp; &nbsp;keybd_event(VK_SHIFT, MapVirtualKey(VK_SHIFT, 0), KEYEVENTF_KEYUP, 0);<br> &nbsp; &nbsp; &nbsp;If ssAlt In M.Shift Then<br> &nbsp; &nbsp; &nbsp; &nbsp;keybd_event(VK_MENU, MapVirtualKey(VK_MENU, 0), KEYEVENTF_KEYUP, 0);<br> &nbsp; &nbsp; &nbsp;If ssCtrl In M.Shift Then<br> &nbsp; &nbsp; &nbsp; &nbsp;keybd_event(VK_CONTROL, MapVirtualKey(VK_CONTROL, 0), KEYEVENTF_KEYUP, 0);<br><br> &nbsp; &nbsp; &nbsp;AttachThreadInput(GetCurrentThreadId, ThreadID, False);<br> &nbsp; &nbsp; &nbsp;ShowWindow(Hwd, SW_RESTORE);<br> &nbsp; &nbsp;End Else<br> &nbsp; &nbsp;Begin<br> &nbsp; &nbsp; &nbsp;SendMsg(Hwd, M);<br> &nbsp; &nbsp; &nbsp;EnumChildWindows(Hwd, @EnumChildWndProc, LongInt(@M));<br> &nbsp; &nbsp;End;<br> &nbsp;End;<br>End;<br><br>End.
 
楼上的写了这么多,其实核心就是:<br>Procedure SendMsg(AhWnd: Hwnd; M: TSMsg);<br>Begin<br> &nbsp;If ssShift In M.Shift Then<br> &nbsp; &nbsp;PostMessage(AhWnd, WM_KEYDOWN, VK_SHIFT, 0);<br> &nbsp;If ssAlt In M.Shift Then<br> &nbsp; &nbsp;PostMessage(AhWnd, WM_KEYDOWN, VK_MENU, 0);<br> &nbsp;If ssCtrl In M.Shift Then<br> &nbsp; &nbsp;PostMessage(AhWnd, WM_KEYDOWN, VK_CONTROL, 0);<br><br> &nbsp;PostMessage(AhWnd, WM_KEYDOWN, M.Key, 0);<br> &nbsp;PostMessage(AhWnd, WM_KEYUP, M.Key, 0);<br><br> &nbsp;If ssShift In M.Shift Then<br> &nbsp; &nbsp;PostMessage(AhWnd, WM_KEYUP, VK_SHIFT, 0);<br> &nbsp;If ssAlt In M.Shift Then<br> &nbsp; &nbsp;PostMessage(AhWnd, WM_KEYUP, VK_MENU, 0);<br> &nbsp;If ssCtrl In M.Shift Then<br> &nbsp; &nbsp;PostMessage(AhWnd, WM_KEYUP, VK_CONTROL, 0);<br>End;<br>这和白河愁的是一样的,根本不能向游戏发送热键,而keybd_event发送热键代码我早已实现,但是用keybd_event必须将游戏窗口前置,设为活动窗口。<br>必须SetForegroundWindow(Hwd);<br><br>我想用sendmessage发送热键是因为当窗口最小化时,窗口还能响应消息。
 
你都没看清楚这个,看完了,测试过了,再说不行吧<br><br>Function EnumChildWndProc(AhWnd: Hwnd; AlParam: Pointer): Boolean; Stdcall;<br>Begin//遍历窗口句柄内的所有控件并发送键消息<br> &nbsp;SendMsg(AhWnd, TSMsg(AlParam^));<br> &nbsp;result := true;<br>End;
 
后退
顶部