Hallo,
ich möchte in Fensterkoordinaten eines anderen Programms einen Klick absetzen.
Folgende Deklarationen:
Aufruf:
Es funktioniert aber nicht - Kein Klick wahrnehmbar
Über Call SetCursorPos(pRelative) wird der Cursor relativ zur Fensterposition richtig gesetzt. Daraus schließe ich, daß FindWindow und ClientToScreen erfolgreich sein.
Ich habe den Code fast komplett aus einem Projekt, was vor 5 Jahren erfolgreich gelaufen ist, deswegen kann ich mir noch weniger erklären wieso es nicht funktioniert. Liegt es am SendMessage ??
Habt ihr eine Idee?
ich möchte in Fensterkoordinaten eines anderen Programms einen Klick absetzen.
Folgende Deklarationen:
VB.NET-Quellcode
- Option Explicit On
- Option Strict On
- Public Class Form1
- <System.Runtime.InteropServices.DllImport("user32.dll", CharSet:=Runtime.InteropServices.CharSet.Auto)>
- Public Shared Function SendMessage(ByVal hWnd As IntPtr, ByVal Msg As Integer, ByVal wParam As Integer, ByVal lParam As IntPtr) As IntPtr
- End Function
- Private Const WM_LBUTTONDOWN As Integer = &H201
- Private Const WM_LBUTTONUP As Integer = &H202
- <System.Runtime.InteropServices.DllImport("user32.dll", SetLastError:=True, CharSet:=System.Runtime.InteropServices.CharSet.Auto)>
- Private Shared Function FindWindow(ByVal lpClassName As String, ByVal lpWindowName As String) As IntPtr
- End Function
- Private Declare Function SetForegroundWindow Lib "User32.Dll" (ByVal hWnd As IntPtr) As IntPtr
- <System.Runtime.InteropServices.DllImport("user32.dll", SetLastError:=True, CharSet:=System.Runtime.InteropServices.CharSet.Auto)>
- Shared Function ClientToScreen(ByVal hwnd As IntPtr, ByRef lpPoint As Point) As Boolean
- End Function
- Private Declare Function SetCursorPos& Lib "user32" (ByVal p As Point)
- Structure PointAPI
- Public x As Integer
- Public y As Integer
- End Structure
- Private Declare Function GetCursorPos Lib "user32" (ByRef lpPoint As PointAPI) As Boolean
- Private Shared Function MakeLParam(ByVal LoWord As Integer, ByVal HiWord As Integer) As IntPtr
- Return New IntPtr((HiWord << 16) Or (LoWord And &HFFFF))
- End Function
- Dim WindowTitle As String = "BlueStacks"
- Dim pStart As New Point(80, 165) 'BlueStacks point to click
Aufruf:
VB.NET-Quellcode
- Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
- Dim w As IntPtr
- w = FindWindow(Nothing, WindowTitle)
- Dim pRelative As New Point
- pRelative = pStart
- Dim c As Boolean = ClientToScreen(w, pRelative)
- Dim ClickPos As IntPtr = MakeLParam(pRelative.X, pRelative.Y)
- SendMessage(w, WM_LBUTTONDOWN, Keys.LButton, ClickPos)
- SendMessage(w, WM_LBUTTONUP, Keys.LButton, ClickPos)
- End Sub
Es funktioniert aber nicht - Kein Klick wahrnehmbar
Über Call SetCursorPos(pRelative) wird der Cursor relativ zur Fensterposition richtig gesetzt. Daraus schließe ich, daß FindWindow und ClientToScreen erfolgreich sein.
Ich habe den Code fast komplett aus einem Projekt, was vor 5 Jahren erfolgreich gelaufen ist, deswegen kann ich mir noch weniger erklären wieso es nicht funktioniert. Liegt es am SendMessage ??
Habt ihr eine Idee?