

![]() | Start a set with this search |
![]() | Include this search in one of my sets |
![]() | Exclude this search from one of my sets |
![]() | Permalink to these results Paste this link in email or IM: |
| Atom feed for tracking future search results Paste this URL into your reader: |
2 messages in net.java.dev.jna.usersInvoke "SendInput" through JNA pressi...| From | Sent On | Attachments |
|---|---|---|
| Ziplies | Jan 20, 2008 4:52 am | |
| Timothy Wall | Jan 20, 2008 6:17 am |

![]() | Permalink for this message Paste this link in email or IM: |
![]() | Permalink for this thread Paste this link in email or IM: |
| Atom feed for this thread Paste this URL into your reader: |
| Subject: | Invoke "SendInput" through JNA pressing LWIN | Actions... |
|---|---|---|
| From: | Ziplies (zipl...@gmail.com) | |
| Date: | Jan 20, 2008 4:52:35 am | |
| List: | net.java.dev.jna.users | |
Hello,
yes, I know such questions may not be seen very well but I am really stuck here.
I want to send a KeyStroke to "SendInput" in user32.dll. I looked up some things at pinvoke and tried the procedure itself in VS2008 and C#. I think I did everything right while copying and changing it to Java and JNA, but it won't work.
The interface is pretty straight forward:
public interface User32 extends StdCallLibrary {
public static final User32 INSTANCE = (User32)Native.loadLibrary("user32", User32.class);
/** * static extern uint SendInput(uint nInputs, INPUT [] pInputs, int cbSize); */ public abstract int SendInput(int nInputs, INPUT[] pInputs, int cbSize); }
As I do not really know what type to use as Structure Array I already tried INPUT[], Structure[], ByRef, PointerType etc pp.
The Structs are: public static class MOUSEINPUT extends Structure { public int dx; public int dy; public int mouseData; public int dwFlags; public int time; public int dwExtraInfo; }
public static class KEYBDINPUT extends Structure { public short wVk; public short wScan; public int dwFlags; public int time; public int dwExtraInfo; }
public static class HARDWAREINPUT extends Structure { public int uMsg; public short wParamL; public short wParamH; }
public static class INPUT extends Structure { public int type; public MOUSEINPUT mi; public KEYBDINPUT ki; public HARDWAREINPUT hi; }
And I call it by: User32 user32 = User32.INSTANCE;
INPUT in = new INPUT(); in.type = 1; in.ki.wVk = 0x5B; // Keycode für LWIN in.ki.dwFlags = 0x00; // Keydown INPUT[] input = (INPUT[])in.toArray(1); int out = user32.SendInput(input.length, input, 28);
INPUT in2 = new INPUT(); in2.type = 1; in2.ki.wVk = 0x5B; // Keycode für LWIN in2.ki.dwFlags = 0x02; // Keydown INPUT[] input2 = (INPUT[])in2.toArray(2); out = user32.SendInput(input2.length, input2, 28);
The 28 come from Marshalling it under C#, but I tried everything over length, size etc pp. If it's input[0].size int out returns 0, if it's 28 int out returns 1, which if I understood correctly means one key is pressed, but still nothing happens.
I tried to do it ByReference as suggested in the APIDoc but same effect.
I really hope someone can enlighten me as I am really out of ideas here. Thanks in advance.
Regards







