Type<br> TSMsg = Packed Record<br> Shift: TShiftState;<br> Key: Word;<br> End;<br><br>Procedure SendMsg(AhWnd: Hwnd; M: TSMsg);<br>Begin<br> If ssShift In M.Shift Then<br> PostMessage(AhWnd, WM_KEYDOWN, VK_SHIFT, 0);<br> If ssAlt In M.Shift Then<br> PostMessage(AhWnd, WM_KEYDOWN, VK_MENU, 0);<br> If ssCtrl In M.Shift Then<br> PostMessage(AhWnd, WM_KEYDOWN, VK_CONTROL, 0);<br><br> PostMessage(AhWnd, WM_KEYDOWN, M.Key, 0);<br> PostMessage(AhWnd, WM_KEYUP, M.Key, 0);<br><br> If ssShift In M.Shift Then<br> PostMessage(AhWnd, WM_KEYUP, VK_SHIFT, 0);<br> If ssAlt In M.Shift Then<br> PostMessage(AhWnd, WM_KEYUP, VK_MENU, 0);<br> If ssCtrl In M.Shift Then<br> PostMessage(AhWnd, WM_KEYUP, VK_CONTROL, 0);<br>End;<br><br>Function EnumChildWndProc(AhWnd: Hwnd; AlParam: Pointer): Boolean; Stdcall;<br>Begin//遍历窗口句柄内的所有控件并发送键消息<br> SendMsg(AhWnd, TSMsg(AlParam^));<br> result := true;<br>End;<br><br><br>定时发送<br>Procedure TFrmMain.TimerTimer(Sender: TObject);<br>Var<br> M: TSMsg;<br> ThreadID: DWord;<br>Begin<br> Inc(CurV);<br> If CurV = Up.IntValue Then<br> Begin<br> CurV := 0;<br> ShortCutToKey(HotKey2.HotKey, M.Key, M.Shift);<br> If ChkGol.Checked Then<br> Begin<br> ThreadID := GetWindowThreadProcessId(Hwd, Nil);<br> AttachThreadInput(GetCurrentThreadId, ThreadID, true);<br> //ShowWindow(Hwd, SW_SHOWNOACTIVATE);<br> SetForegroundWindow(Hwd);<br> If ssShift In M.Shift Then<br> keybd_event(VK_SHIFT, MapVirtualKey(VK_SHIFT, 0), 0, 0);<br> If ssAlt In M.Shift Then<br> keybd_event(VK_MENU, MapVirtualKey(VK_MENU, 0), 0, 0);<br> If ssCtrl In M.Shift Then<br> keybd_event(VK_CONTROL, MapVirtualKey(VK_CONTROL, 0), 0, 0);<br><br> keybd_event(M.Key, MapVirtualKey(M.Key, 0), 0, 0);<br> keybd_event(M.Key, MapVirtualKey(M.Key, 0), KEYEVENTF_KEYUP, 0);<br><br> If ssShift In M.Shift Then<br> keybd_event(VK_SHIFT, MapVirtualKey(VK_SHIFT, 0), KEYEVENTF_KEYUP, 0);<br> If ssAlt In M.Shift Then<br> keybd_event(VK_MENU, MapVirtualKey(VK_MENU, 0), KEYEVENTF_KEYUP, 0);<br> If ssCtrl In M.Shift Then<br> keybd_event(VK_CONTROL, MapVirtualKey(VK_CONTROL, 0), KEYEVENTF_KEYUP, 0);<br><br> AttachThreadInput(GetCurrentThreadId, ThreadID, False);<br> ShowWindow(Hwd, SW_RESTORE);<br> End Else<br> Begin<br> SendMsg(Hwd, M);<br> EnumChildWindows(Hwd, @EnumChildWndProc, LongInt(@M));<br> End;<br> End;<br>End;