[英]JNA / WinAPI. Simulating mouse click moves mouse cursor and doesn't return it back to the start position
[英]Mouse click with JNA
我正試圖用JNA模擬鼠標點擊窗口。
public class App {
public static final int WM_LBUTTONUP = 514;
public static final int WM_LBUTTONDOWN = 513;
public static final int WM_LBUTTONDBLCLK = 0x203;
static int WM_CLOSE = 0x10;
final static String winTitle = "Untitled - Notepad";
public static void main(String[] args) throws InterruptedException {
User32Extra user32 = (User32Extra) Native.loadLibrary("user32", User32Extra.class, W32APIOptions.DEFAULT_OPTIONS);
WinDef.HWND hwnd = user32.FindWindow(null, winTitle);
user32.SetForegroundWindow(hwnd);
Thread.sleep(1000);
long y = 77 + (22 << 16);//x + (y << 16)
WinDef.LPARAM l = new WinDef.LPARAM(y);
WinDef.WPARAM w = new WinDef.WPARAM(0);
user32.PostMessage(hwnd, WM_LBUTTONDOWN, w, l);
Thread.sleep(1000);
user32.PostMessage(hwnd, WM_LBUTTONUP, w, l);
}
}
它找到窗戶並把它帶到前面。 但鼠標單擊不起作用。 也發送WM_CLOSE工作。 鼠標點擊有什么問題? 測試計算器和記事本。 坐標是相對於窗口的。
只是猜測:點擊事件不應傳遞到主窗口,而應傳遞到目標按鈕對象本身。 在給定的坐標上,當實際點擊發生時,按鈕位於主窗口上方“隱藏”它。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.