我正在尝试用Java创建一个自动点击器(只有我知道的语言,我刚刚学习了Threads).我想让applet在它自己的窗口中打开(不在网页上),我希望能够在没有选择窗口的情况下使用空格键启动和停止程序,这样我就可以在另一个程序上使用自动点击器并且能够在没有alt-f4ing一堆东西的情况下阻止它.
有什么可以推荐给我的,可以帮助我吗?或者你有什么建议吗?
迟到的答案,但希望有帮助:)
你可以使用JNA,这是一个很棒的!
得到JNA(jna.jar)
在表单中为User32(User32.dll)创建自己的映射
public interface User32 extends StdCallLibrary { User32 INSTANCE = (User32) Native.loadLibrary("User32", User32.class, Options.UNICODE_OPTIONS); // dwWakeMask Constants public 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); }
只需查看以下页面,就可以清楚了解工作原理:
ħ**号码://msdn.microsoft.com/en-us/library/ms646309%28VS.85%29.aspx
ħ**号码://msdn.microsoft.com/en-us/library/ms684242%28VS.85%29.aspx
检查此页面以查看可以注册回调的关键常量
ħ**号码://msdn.microsoft.com/en-us/library/dd375731%28v=VS.85%29.aspx
创建一个这样的测试程序:
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规则Stefano