KnowledgeHub
Questions
Tags
Users
Search
Alex Rivera
|
Logout
Edit Question
Title
Body
How to interact with the Windows API using Java and the JNA (Java Native Access)?. I'm trying to make the mouse do something by queuing a mouse event on the mouse input stream, and the code works, in that the SendInput(...) method returns 1 suggesting that it has successfully queued the event, but yet the mouse itself does nothing. My SSCCE : Edit: edited to fill in the dwFlags field. I've tried several combinations of constants either by themselves or bit-or combined without success still. Again, the SendInput method returns 1 as it should suggesting a functioning method, but the mouse doesn't budge: import com.sun.jna.Native; import com.sun.jna.platform.win32.WinDef.*; import com.sun.jna.platform.win32.WinUser.*; import com.sun.jna.win32.StdCallLibrary; public class MouseUtils { public interface User32 extends StdCallLibrary { public static final long MOUSEEVENTF_MOVE = 0x0001L; public static final long MOUSEEVENTF_VIRTUALDESK = 0x4000L; public static final long MOUSEEVENTF_ABSOLUTE = 0x8000L; User32 INSTANCE = (User32) Native.loadLibrary("user32", User32.class); DWORD SendInput(DWORD dWord, INPUT[] input, int cbSize); } public static void main(String[] args) { INPUT input = new INPUT(); input.type = new DWORD(INPUT.INPUT_MOUSE); input.input.mi.dx = new LONG(500); input.input.mi.dy = new LONG(500); input.input.mi.mouseData = new DWORD(0); input.input.mi.dwFlags = new DWORD(User32.MOUSEEVENTF_MOVE | User32.MOUSEEVENTF_VIRTUALDESK | User32.MOUSEEVENTF_ABSOLUTE); // input.input.mi.dwFlags = new DWORD(0x8000L); input.input.mi.time = new DWORD(0); INPUT[] inArray = {input}; int cbSize = input.size(); // mouse input struct size DWORD nInputs = new DWORD(1); // number of inputs DWORD result = Use
Tags (comma-separated)
Save Edits
Cancel