gpt4 book ai didi

没有打开窗口的Java Keylistener?

转载 作者:搜寻专家 更新时间:2023-11-01 02:18:40 26 4
gpt4 key购买 nike

我正在尝试用 Java 创建一个自动点击器(我只知道这门语言,而且我刚学过 Threads)。我想让小程序在它自己的窗口中打开(而不是在网页上),并且我希望能够在不选择窗口的情况下使用空格键启动和停止程序,以便我可以在另一个程序上使用自动点击器并且无需 alt-f4 一堆东西就可以停止它。

有什么可以帮助我解决这个问题的吗?或者您有什么建议吗?

最佳答案

迟到的答案,但希望有帮助:)

您可以使用 JNA,这是小菜一碟!!

  1. 获取 JNA (jna.jar)
  2. 在表单中为 User32 (User32.dll) 创建您自己的映射

    public interface User32 extends StdCallLibrary {User32 INSTANCE = (User32) Native.loadLibrary("User32", User32.class,   Options.UNICODE_OPTIONS);// dwWakeMask Constantspublic static final int QS_ALLEVENTS = 0x04BF;public static final int QS_ALLINPUT = 0x04FF;public static final int QS_ALLPOSTMESSAGE = 0x0100;public static final int QS_HOTKEY = 0x0080;public static final int QS_INPUT = 0x407;public static final int QS_KEY = 0x0001;public static final int QS_MOUSE = 0x0006;public static final int QS_MOUSEBUTTON = 0x0004;public static final int QS_MOUSEMOVE = 0x0002;public static final int QS_PAINT = 0x0020;public static final int QS_POSTMESSAGE = 0x0008;public static final int QS_RAWINPUT = 0x0400;public static final int QS_SENDMESSAGE = 0x0040;public static final int QS_TIMER = 0x0010;public static final int INFINITE =    0xFFFFFFFF;/*DWORD WINAPI MsgWaitForMultipleObjects(__in  DWORD nCount,__in  const HANDLE *pHandles,__in  BOOL bWaitAll,__in  DWORD dwMilliseconds,__in  DWORD dwWakeMask);*/int MsgWaitForMultipleObjects(int nCount, Pointer pHandles, boolean bWaitAll, int dwMilliSeconds, int dwWakeMask);/* fsModifiers vaues */public static final int MOD_ALT = 0x0001;public static final int MOD_CONTROL = 0x0002;public static final int MOD_NOREPEAT = 0x4000;public static final int MOD_SHIFT = 0x0004;public static final int MOD_WIN = 0x0008;/* BOOL WINAPI RegisterHotKey(__in_opt  HWND hWnd,__in      int id,__in      UINT fsModifiers,__in      UINT vk);*/boolean RegisterHotKey(Pointer hWnd, int id, int fsModifiers, int vk);}
  3. 只需查看以下页面,即可清楚地了解幕后工作原理:

h**p://msdn.microsoft.com/en-us/library/ms646309%28VS.85%29.aspx

h**p://msdn.microsoft.com/en-us/library/ms684242%28VS.85%29.aspx

  1. 查看此页面以了解您可以为其注册回调的关键常量有哪些

h**p://msdn.microsoft.com/en-us/library/dd375731%28v=VS.85%29.aspx

  1. 像这样创建一个测试程序:
User32 user32 = User32.INSTANCE;boolean res = user32.RegisterHotKey(Pointer.NULL, 9999, User32.MOD_ALT | User32.MOD_CONTROL, WINUSER.VK_LEFT);if(!res)  System.out.println("Couldn't register hotkey");System.out.println("Starting and waiting");user32.MsgWaitForMultipleObjects(0, Pointer.NULL, true, User32.INFINITE, User32.QS_HOTKEY);System.out.println("Ending");

User32.INFINITE 是一个未记录的常量,值为 0xFFFFFFFF

很抱歉将 http 链接重命名为 h**p :) Stackoverflow 规则斯特凡诺

关于没有打开窗口的Java Keylistener?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/696170/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com