How to implement following class in java project (Eclipse)?

I am trying to use following class in new project with standard Java libraries.  User32 is not recognized.

public class CWMouseHook {

      final User32 USER32INST;
    private static LowLevelMouseProc mouseHook;

    public CWMouseHook() {
        if(!Platform.isWindows()) {
            throw new UnsupportedOperationException("Not supported on this platform.");
        }
        USER32INST = User32.INSTANCE;
        mouseHook = hookTheMouse();
        Native.setProtected(true);
    }
 
    private HHOOK hhk;
    private boolean isHooked = false;
 
    public static final int WM_LBUTTONDOWN = 513;
    public static final int WM_LBUTTONUP = 514;
    public static final int WM_RBUTTONDOWN = 516;
    public static final int WM_RBUTTONUP = 517;
    public static final int WM_MBUTTONDOWN = 519;
    public static final int WM_MBUTTONUP = 520;
 
    public void unsetMouseHook() {
        USER32INST.UnhookWindowsHookEx(hhk);
        isHooked = false;
        System.out.println("Mouse hook is unset.");
    }
 
    public boolean isIsHooked() {
        return isHooked;
    }
 
    public void setMouseHook() {
        Thread mousehook_thread = new Thread(new Runnable() {
            @Override
            public void run()  {
                try {
                    if(!isHooked) {
                        hhk = USER32INST.SetWindowsHookEx(
                                User32.WH_MOUSE_LL,
                                mouseHook,
                                Kernel32.INSTANCE.GetModuleHandle(null),
                                0);
 
                        isHooked = true;
 
                        System.out.println("Mouse hook is set. Click anywhere.");
                        // message dispatch loop (message pump)
                        MSG msg = new MSG();
                        while ((USER32INST.GetMessage(msg, null, 0, 0)) != 0) {
                            USER32INST.TranslateMessage(msg);
                            USER32INST.DispatchMessage(msg);
                            if (!isHooked)
                                break;
                        }
                    } else
                        System.out.println("The Hook is already installed.");
                } catch (Exception e) { System.err.println("Caught exception in MouseHook!"); }
            }
        });
        mousehook_thread.start();
    }
 
    private interface LowLevelMouseProc extends HOOKPROC {
        LRESULT callback(int nCode, WPARAM wParam, MOUSEHOOKSTRUCT lParam);
    }
 
    private LowLevelMouseProc hookTheMouse() {
        return new LowLevelMouseProc() {
            @Override
            public LRESULT callback(int nCode, WPARAM wParam, MOUSEHOOKSTRUCT info) {
                if (nCode >= 0) {
                    switch(wParam.intValue()) {
                        case CWMouseHook.WM_LBUTTONDOWN:
                            System.out.println("L ["+info.pt.x+","+info.pt.y+"]");
                            break;
                        case CWMouseHook.WM_RBUTTONDOWN:
                            System.out.println("R ["+info.pt.x+","+info.pt.y+"]");
                            break;
                        case CWMouseHook.WM_MBUTTONDOWN:
                            System.out.println("M ["+info.pt.x+","+info.pt.y+"]");
                            break;
                        default:
                            break;
                    }
                }
                return USER32INST.CallNextHookEx(hhk, nCode, wParam, info.getPointer());
            }
        };
    }
 
    public class Point extends Structure {
        public class ByReference extends Point implements Structure.ByReference {};
        public NativeLong x;
        public NativeLong y;
    }
 
    public static class MOUSEHOOKSTRUCT extends Structure {
        public static class ByReference extends MOUSEHOOKSTRUCT implements Structure.ByReference {};
 
        public POINT pt;
        public HWND hwnd;
        public int wHitTestCode;
        public ULONG_PTR dwExtraInfo;
    }
}
LVL 13
AshokSr. Software EngineerAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

for_yanCommented:
I don't think this is the standard java library - you probably want to use some
microsft package - you should treat it as external library and find ocrresponding jar
(hope the links below could help):

http://jcs.mobile-utopia.com/jcs/55085_User32.java

http://javadevelopersdiary.blogspot.com/2008/03/call-findwindow-method-of-user32dll.html
0
CEHJCommented:
Looks like you need JNA for that

http://jna.java.net
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
AshokSr. Software EngineerAuthor Commented:
CEHJ,

You are right.  I tried to find the link for it and got some wrong link with VIRUS ATTACK.
The link you provided is safe.
I will try this.

Thanks
0
Introduction to Web Design

Develop a strong foundation and understanding of web design by learning HTML, CSS, and additional tools to help you develop your own website.

AshokSr. Software EngineerAuthor Commented:
CEJH,

I cannot (figure out or) remove all errors after adding both JAR files in the project and trying to add necessary imports.

Thanks
0
CEHJCommented:
a. what ide?
b. which jars?
c.  what are the urls of the jar downloads?
0
AshokSr. Software EngineerAuthor Commented:
for_yan,

How do I download "com.ms.win32"?

Thanks
0
AshokSr. Software EngineerAuthor Commented:
a) Eclipse IDE
b) jna & platform
c) http://jna.java.net
0
CEHJCommented:
You're missing additional sources. Something like the following:

http://stackoverflow.com/questions/3078646/jna-keyboard-hook-in-windows
0
CEHJCommented:
:)
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Java

From novice to tech pro — start learning today.