JNA mouse click

I am trying to simulate a mouse click in a window using 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); } } 

He will find the window and bring it to the fore. but mouse click does not work. Also sending is WM_CLOSE. What is wrong with a mouse click? Tested on a calculator and notepad. The coordinates relate to the window.

+4
source share
1 answer

Just a wild assumption: click events should not be delivered to the main window, but the objects of the destination button themselves. At the given coordinates, the button lies above the main window, "hiding" it when a real click occurs.

+1
source

Source: https://habr.com/ru/post/1396622/


All Articles