hi, i`m a new member, hows you? I`ve a question and i hope you can help me. Is possible (using jna)detect with a global hook the cursor change? In my application i must detect when the cursor is the hand cursor. Sorry for my bad English
I know of no Java GUI event to signal the change of cursor shape. If by "jna" you mean some native code should detect this (via JNI) then it would depend on the underlying opoerating system whether and how it supports such an event. The solution would thus not be portable (if one exists: as a cross-platform developer I usually avoid platform specific solutions). Your task is not very clearly described, so there might be additional details required to find pointers towards a reasonable solution.
E.g. if your application is a Java program, is it not this program that changes the cursor shape on behalf of some event? And is it not that very event to which you want to react? So the best solution for you might be listening to that event instead of observing the mouse cursor. I cannot think of a good reason why changing the mouse cursor to "hand shape" would have a universally valid and well known meaning. Note also that an application can define ANY bitmap to be used as a mouose cursor: how could we have a general piece of code that figures out if that bitmap looks "like a hand" to a human?
However, I can see that class Cursor caches the default variants of the usual shapes, so that e.g. Cursor.getPredefinedCursor(Cursor.HAND_CURSOR) would always give you the same prefabricated instance of a "default hand cursor". Now, if you know the window/component of your application where the occurrence of a "hand cursor" has some meaning for you, then you could register a mouse listener on such a component which reacts to enter/exit events of the mouse (or maybe also movements): presumably the application changes cursor shape in response to these events and if it uses just the abovementioned "prefabricated instance" from the cache, you could call Component#getCursor and check if you're getting that instance. Maybe that works for you... But I still think that would be an ugly workaround and there should be an event that is the "real" event that you want to listen for: Why would anyone assign a business logic meaning to a mere change of pointer shape?
nobody can halp me???
Your use of this web site or any of its content or software indicates your agreement to be bound by these Terms of Participation.
Copyright © 2015, Oracle and/or its affiliates. All rights reserved. Oracle and Java are registered trademarks of Oracle and/or its affiliates. Other names may be trademarks of their respective owners.