运维开发网

Java 用JNA单击鼠标

运维开发网 https://www.qedev.com 2020-03-03 13:40 出处:网络 作者:运维开发网整理
我正试图用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 =
我正试图用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工作.

鼠标点击有什么问题?

测试计算器和记事本.

坐标是相对于窗口的.

只是猜测:点击事件不应传递到主窗口,而应传递到目标按钮对象本身.在给定的坐标上,当实际点击发生时,按钮位于主窗口上方“隐藏”它.
0

精彩评论

暂无评论...
验证码 换一张
取 消