1 message in net.java.dev.jna.users[jna-users] Re: LowLevelMouseProc doe...
FromSent OnAttachments
Timothy WallNov 5, 2008 5:39 am 
Actions with this message:
Paste this link in email or IM:
Paste this link in email or IM:
Atom feed for this thread
Paste this URL into your reader:
Subject:[jna-users] Re: LowLevelMouseProc doesn't workActions...
From:Timothy Wall (twal@dev.java.net)
Date:Nov 5, 2008 5:39:16 am
List:net.java.dev.jna.users

You don't say what's wrong or what isn't working. But you have at least two things wrong here: you have two callback methods defined in one callback interface, and if you look at the LL keyboard hook example, you'll see that you need to read the windows message queue in order to get events flowing.

On Nov 5, 2008, at 2:22 AM, bao bao wrote:

hey, sir, i have registered LowLevelMouseProc, but it doesn't work. Can you help me? Regards, lefish

Here is my code:

import com.overhi.keyboard.MK.User32B.LowLevelMouseProc; import com.overhi.keyboard.MK.User32B.MSLLHOOKSTRUCT; import com.sun.jna.Native; import com.sun.jna.NativeLong; import com.sun.jna.Structure; import com.sun.jna.examples.win32.Kernel32; import com.sun.jna.examples.win32.User32; import com.sun.jna.examples.win32.User32.HHOOK; import com.sun.jna.examples.win32.W32API.HMODULE; import com.sun.jna.examples.win32.W32API.LPARAM; import com.sun.jna.examples.win32.W32API.LRESULT; import com.sun.jna.examples.win32.W32API.WPARAM;

public class MK {

public interface User32B extends User32 { User32B INSTANCE = (User32B) Native.loadLibrary("user32", User32B.class, DEFAULT_OPTIONS);

class POINT extends Structure { public NativeLong x; public NativeLong y;

public POINT() { }

public POINT(NativeLong x, NativeLong y) { this.x = x; this.y = y; } }

class MSLLHOOKSTRUCT extends Structure { public POINT pt = new POINT(); public int mouseData; public int flags; public int time; public ULONG_PTR dwExtraInfo;

public MSLLHOOKSTRUCT() { } }

interface LowLevelMouseProc extends HOOKPROC { LRESULT callback(int nCode, WPARAM wParam, MSLLHOOKSTRUCT lParam);

LRESULT callback(int nCode, WPARAM wParam, LPARAM lParam); } }

private LowLevelMouseProc mouseHook; private HHOOK hhk;

User32B user32b = User32B.INSTANCE; HMODULE hMod = Kernel32.INSTANCE.GetModuleHandle(null); boolean quit;

public MK() { }

private void setHook() {

mouseHook = new LowLevelMouseProc() { @Override public LRESULT callback(int nCode, WPARAM wParam, MSLLHOOKSTRUCT info) { if (nCode >= 0) { System.out.println(info.pt.x); System.out.println(1); } return user32b.CallNextHookEx(hhk, nCode, wParam, info .getPointer()); }

@Override public LRESULT callback(int nCode, WPARAM wParam, LPARAM lParam) { if (nCode >= 0) { System.out.println(1); } return user32b.CallNextHookEx(hhk, nCode, wParam, lParam); }

}; hhk = user32b.SetWindowsHookEx(User32.WH_MOUSE, mouseHook, hMod, 0); System.out.println(hhk == null); System.out.println(mouseHook == null); new Thread() {

public void run() { while (!quit) { try { Thread.sleep(100); } catch (Exception e) { e.printStackTrace(); } } System.err.println("unhook and exit"); user32b.UnhookWindowsHookEx(hhk); System.exit(0); } }.start(); }

/** * @param args */ public static void main(String[] args) { MK m = new MK(); m.setHook(); }