本帖最后由 zch11230 于 2012-4-29 11:05 编辑
这个是我查资料前自己想的 后台发送
查资料查到版主们也讨论过这个问题 而且解决了目标窗口失去焦点的问题 只能说版主都太强大了
http://www.autoitx.com/thread-17127-1-1.html
#include <WinAPI.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
Opt("GUIOnEventMode", 1)
Global $SendWinHwnd, $SendCrlHwnd
#Region ### START Koda GUI section ### Form=
$Form1 = GUICreate("Form1", 430, 50, @DesktopWidth - 440, @DesktopHeight - 120)
GUISetOnEvent($GUI_EVENT_CLOSE, "Form1Close")
$Button1 = GUICtrlCreateButton("1", 10, 20, 60, 20)
GUICtrlSetOnEvent(-1, "Button1Click")
$Button2 = GUICtrlCreateButton("2", 80, 20, 60, 20)
GUICtrlSetOnEvent(-1, "Button2Click")
$Button3 = GUICtrlCreateButton("3", 150, 20, 60, 20)
GUICtrlSetOnEvent(-1, "Button3Click")
$Button4 = GUICtrlCreateButton("A", 220, 20, 60, 20)
GUICtrlSetOnEvent(-1, "Button4Click")
$Button5 = GUICtrlCreateButton("B", 290, 20, 60, 20)
GUICtrlSetOnEvent(-1, "Button5Click")
$Button6 = GUICtrlCreateButton("C", 360, 20, 60, 20)
GUICtrlSetOnEvent(-1, "Button6Click")
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###
WinSetOnTop(HWnd($Form1), "", 1)
While 1
$FousHwnd = _WinAPI_GetForegroundWindow()
If $FousHwnd <> $Form1 Then
;~ $SendWinHwnd = $FousHwnd
$SendCrlHwnd = ControlGetHandle(HWnd($FousHwnd), "", ControlGetFocus(HWnd($FousHwnd)))
EndIf
;~ ConsoleWrite($SendCrlHwnd&@CRLF)
Sleep(200)
WEnd
Func Button1Click()
;~ WinActivate(HWnd($SendWinHwnd))
_WinAPI_PostMessage($SendCrlHwnd, $WM_KEYDOWN, 0x31, 0)
EndFunc
Func Button2Click()
_WinAPI_PostMessage($SendCrlHwnd, $WM_KEYDOWN, 0x32, 0)
EndFunc
Func Button3Click()
_WinAPI_PostMessage($SendCrlHwnd, $WM_KEYDOWN, 0x33, 0)
EndFunc
Func Button4Click()
_WinAPI_PostMessage($SendCrlHwnd, $WM_KEYDOWN, 0x41, 0)
EndFunc
Func Button5Click()
_WinAPI_PostMessage($SendCrlHwnd, $WM_KEYDOWN, 0x42, 0)
EndFunc
Func Button6Click()
_WinAPI_PostMessage($SendCrlHwnd, $WM_KEYDOWN, 0x43, 0)
EndFunc
Func Form1Close()
Exit
EndFunc
|