slbmeh Posted March 21, 2012 Share Posted March 21, 2012 (edited) I have code that I can use to send mouse click signals to a window while it is minimized. expandcollapse popupFunc __SendMessageCall($WinHandle, $iAction, $iParam, $lCoords) DllCall("user32.dll", "int", "SendMessage", _ "hwnd", $WinHandle, _ "int", $iAction, _ "int", $iParam, _ "long", $lCoords) EndFunc Func __MouseClickValue($sButton) Local $MK_LBUTTON = 0x0001 Local $WM_LBUTTONDOWN = 0x0201 Local $WM_LBUTTONUP = 0x0202 Local $MK_RBUTTON = 0x0002 Local $WM_RBUTTONDOWN = 0x0204 Local $WM_RBUTTONUP = 0x0205 Local $Primary, $Secondary, $RealButton Local $ButtonVal[3] $RealButton = $Button If $Button = "" OR _ $Button = "primary" OR _ $Button = "main" OR _ $Button = "secondary" OR _ $Button = "menu" Then $RegSetting = RegRead("HKEY_CURRENT_USERControl PanelMouse", "SwapMouseButtons") If $RegSetting = 1 Then $Primary = "right" $Secondary = "left" Else $Primary = "left" $Secondary = "right" EndIf Select Case $Button = "" OR $Button = "primary" OR $Button = "main" $RealButton = $Primary Case $Button = "secondary" OR $Button = "menu" $RealButton = $Secondary EndSelect EndIf Switch $RealButton Case "left" $ButtonID = $MK_LBUTTON $ButtonDown = $WM_LBUTTONDOWN $ButtonUp = $WM_LBUTTONUP Case "right" $ButtonID = $MK_RBUTTON $ButtonDown = $WM_RBUTTONDOWN $ButtonUp = $WM_RBUTTONUP EndSwitch $ButtonVal[0] = $ButtonID $ButtonVal[1] = $ButtonDown $ButtonVal[2] = $ButtonUp Return $ButtonVal EndFunc Func _SendMouseMove($Window, $X = "", $Y = "", $Speed = 10) Local $WM_MOUSEMOVE = 0x0200 Local $WinHandle = WinGetHandle($Window) Local $i = 0 Local $MouseCoord = MouseGetPos() $StartX = $MouseCoord[0] $StartY = $MouseCoord[1] If $X = "" OR $Y = "" Then $X = $MouseCoord[0] $Y = $MouseCoord[1] EndIf $StopX = $X $StopY = $Y If $Speed > 0 Then $JumpX = ($StopX - $StartX) / $Speed $JumpY = ($StopY - $StartY) / $Speed For $i = 1 to $Speed $X = $X + $JumpX $Y = $Y + $JumpY $lCoords = __MakeLong($X, $Y) __SendMessageCall($WinHandle, $WM_MOUSEMOVE, 0, $lCoords) Sleep(10) Next EndIf $lCoords = __MakeLong($StopX, $StopY) __SendMessageCall($WinHandle, $WM_MOUSEMOVE, 0, $lCoords) EndFunc Func _SendClick($Window, $Button = "primary", $X = "", $Y = "", $Clicks = 1) Local $i = 0 Local $ButtonVal = __MouseClickValue($Button) Local $WinHandle = WinGetHandle($Window) If $X = "" OR $Y = "" Then $MouseCoord = MouseGetPos() $X = $MouseCoord[0] $Y = $MouseCoord[1] EndIf Local $lCoords = _MakeLong($X, $Y) For $i = 1 to $Clicks _SendMouseMove($Window, $X, $Y) __SendMessageCall($WinHandle, $ButtonVal[1], $ButtonVal[0], $lCoords) __SendMessageCall($WinHandle, $ButtonVal[2], $ButtonVal[0], $lCoords) Next EndFunc Func _SendClickDrag($Window, $Button = "primary", $X1 = "", $Y1 = "", $X2 = "", $Y2 = "", $Speed = 10) Local $MK_LBUTTON = 0x0001 Local $WM_LBUTTONDOWN = 0x0201 Local $WM_LBUTTONUP = 0x0202 Local $MK_RBUTTON = 0x0002 Local $WM_RBUTTONDOWN = 0x0204 Local $WM_RBUTTONUP = 0x0205 Local $WM_MOUSEMOVE = 0x0200 Local $i = 0 Local $WinHandle = WinGetHandle($Window) Local $Primary, $Secondary, $RealButton $RealButton = $Button If $Button = "" OR _ $Button = "primary" OR _ $Button = "main" OR _ $Button = "secondary" OR _ $Button = "menu" Then $RegSetting = RegRead("HKEY_CURRENT_USERControl PanelMouse", "SwapMouseButtons") If $RegSetting = 1 Then $Primary = "right" $Secondary = "left" Else $Primary = "left" $Secondary = "right" EndIf Select Case $Button = "" OR $Button = "primary" OR $Button = "main" $RealButton = $Primary Case $Button = "secondary" OR $Button = "menu" $RealButton = $Secondary EndSelect EndIf Switch $RealButton Case "left" $Button = $MK_LBUTTON $ButtonDown = $WM_LBUTTONDOWN $ButtonUp = $WM_LBUTTONUP Case "right" $Button = $MK_RBUTTON $ButtonDown = $WM_RBUTTONDOWN $ButtonUp = $WM_RBUTTONUP EndSwitch If $X = "" OR $Y = "" Then $MouseCoord = MouseGetPos() $X = $MouseCoord[0] $Y = $MouseCoord[1] EndIf $CoordsLong = _MakeLong($X, $Y) For $i = 1 to $Clicks _SendMessageCall($WinHandle, $WM_MOUSEMOVE, 0, $CoordsLong) _SendMessageCall($WinHandle, $ButtonDown, $Button, $CoordsLong) _SendMessageCall($WinHandle, $ButtonUp, $Button, $CoordsLong) Next EndFunc I am curious if it is possible to create an embedded instance of IE on a tab and send clicks to it (not html interaction, but java, flash, silverlight, etc) without the tab being currently active. Has anyone done anything similar? Is there an easier or better way to do this other than sending clicks to my own interface? Edit: Can a moderator please move this post to General Support? I misunderstood the subforum descriptions and posted here because I was thinking about COM in my application. Edited March 21, 2012 by slbmeh Link to comment Share on other sites More sharing options...
DeathRow Posted March 30, 2012 Share Posted March 30, 2012 BUMP! Anybody with any solution? Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now