Quantcast
Channel: VBForums - Visual Basic 6 and Earlier
Viewing all articles
Browse latest Browse all 21237

Trying to use mouse_event API. What am I doing wrong?

$
0
0
Code:

Private Type POINTAPI
 x As Integer
 y As Integer
End Type

Private Declare Sub mouse_event Lib "user32" (ByVal dwFlags As Long, ByVal dX As Long, ByVal dY As Long, ByVal dwData As Long, ByVal dwExtraInfo As Long)

Private Declare Function SetCursorPos Lib "user32" (ByVal x As Integer, ByVal y As Integer) As Long

Private Declare Function ScreenToClient Lib "user32" (ByVal hwnd As Long, lpPoint As POINTAPI) As Long

Private Const MOUSEEVENTF_LEFTDOWN = &H2
Private Const MOUSEEVENTF_LEFTUP = &H4


Private Sub Command1_Click()
 Dim p As POINTAPI
 
 ScreenToClient txtMessage.hwnd, p

 p.x = txtMessage.Left + 10
 p.y = txtMessage.Top + 10

 SetCursorPos p.x, p.y

 mouse_event MOUSEEVENTF_LEFTDOWN, 0, 0, 0, 0
 mouse_event MOUSEEVENTF_LEFTUP, 0, 0, 0, 0
End Sub

The mouse arrow always winds up too far left and too far up from the txtMessage box

Viewing all articles
Browse latest Browse all 21237

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>