1

I am attempting to monitor mouse events with Low Level Mouse Hook in Java using the JNA (or Java Native Access) to check for the LLMHF_INJECTED flag. I cant figure out for how to cast the lparam pointer to a MSLLHOOKSTRUCT like I would in c++. This is what my current callback function looks like.

LowLevelMouseProc LLMP = new LowLevelMouseProc() {
    public LRESULT callback(int nCode, WPARAM wParam, LPARAM lParam) {


        if (nCode >= 0){

        }

        Pointer ptr = lParam.toPointer();
        long peer = Pointer.nativeValue(ptr); 
        return User32.INSTANCE.CallNextHookEx(hook, nCode, wParam,new LPARAM(peer));
    }
};

I also have the hook struct outlined in its own class as shown below:

public class MSLLHOOKSTRUCT extends Structure{

public static class ByReference extends MSLLHOOKSTRUCT implements Structure.ByReference {};

    public POINT pt;
    public DWORD mouseData;
    public DWORD flags;
    public DWORD time;
    public ULONG_PTR dwExtraInfo;

    @Override
    protected List<String> getFieldOrder() {
        return null;
    }
}

I just need to know how to map the pointer to the MSLLHOOKSTRUCT.

Max Vollmer
  • 8,412
  • 9
  • 28
  • 43
Jmercer5
  • 11
  • 1
  • 1
    You could just add a mapping for `CallNextHookEx` which takes `MSLLHOOKSTRUCT` as a final argument. JNA will take care of the rest. – technomage Sep 20 '18 at 19:08
  • @technomage can you give me an example, because everything I try doesn't seem to work. I'm quit new to JNA in general. – Jmercer5 Sep 24 '18 at 12:23
  • See the answer to [this question](https://stackoverflow.com/questions/3078646/jna-keyboard-hook-in-windows) – technomage Sep 24 '18 at 22:17

0 Answers0