I need to get the absolute location of mouse after a click on the screen. I've already searched on the web but the only solution I have found uses this method:
MouseInfo.getPointerInfo().getLocation()
which gets the position independently from the click.
Otherwise, i have to use an EventListener to check out when the mouse is clicked, but the problem is that listeners are related to a component, while i need the absolute location.
How can i solve this?
This is an OS dependent feature. As far as I understand your question, you don't have a GUI or you don't want to add a listener to your GUI components. JVM will only receive clicks for components that are related to it.
Here you have to write some native code to hook to events that you want on your own, or you should use a library like jnativehook that does the same thing for you and you don't need to write code for Linux, Mac OS X and Windows.
Related
I have the following simple question. Is it possible for someone to have two Java Swing application windows from which events could be captured?
I have the following scenario. I have an app which runs on a touch enabled device running Windows 7. Said app spawns another child JFrame. Now, if I click on the parent frame, I get the window's focus and I can perform actions. Doing the same on the child frame also does the same getting the focus from the parent.
What I want to do, is to be able to handle click events on both screens - that is don't block the other frame when someone is interacting with the other one.
Is there a way to do something like that?
I want to capture the keyboard and mouse click event on my window everywhere suppose I have opened browser or opened notepad or some other tools, it should not be effected. I know to do one way this with the batch file but I am trying to do this thruogh java libraries. I tried with AWT and swing but they can only capture within their frame.
Please suggest me approach for captuering keyboard and mouse event through java. Any help will be appriciated.
This is problematic the moment you want to run it on different platforms. For Windows, you would need to use Java Native Interface directly to access dll's, or use ready libraries such as this.
These listeners in general are not trivial to implement, but there are some good examples in test sections of linked gitpage.
I know that Robot class in java is used to generateInputevents such as mouseMove,press and release and also keyevents ,i know only the functionality i.e if i call mouseMove(x,y) mousepointer will move to the (x,y) position.I don't know ,Actually what happens inside i.e what are the steps take by JVM to interact with os to move the mouse pointer and other events?
The nice thing about the Java library is that a lot of it is opensource. A quick glance through it shows that on Unix-ish platforms it creates a XToolkit and then there's a lot of interfacing with the X11 library to send keyboard and mouse events.
In particular, all of the events are eventually dispatched to sun.awt.X11.XRobotPeer, who then dispatches them to awt_Robot.c who then calls various X11 functions to produce particular events.
I am developing a Swing application in Java. The program is to be run on dedicated Windows 7 Touch Screen machines, and as far as I know, this program should be the only thing running on them under normal operation.
I've noticed that Windows 7's touch screen interface has this thing where it will hold back mousedown events. Due to the "tap-and-hold right click" gesture, Windows 7 won't actually send the application a mouse down event until:
the user "touch ups" (raise their finger from a touch, at which point both down and up are sent)
moves their finger (at which point the click becomes a drag)
or the right click circle gesture times out (after about 5-6 seconds)
Trivially, this means that buttons don't look depressed on the application until the mouse down event is sent (and never draw depressed at all with a quick tap). But, recently, more seriously, this means functionality that requires a press-and-hold cannot happen without major amounts of confusion to the average user.
At this point in development it is far too late to turn around and start from scratch with one of the many touch libraries offered on other questions. (They require redoing the entire application in their component hierarchy, and that simply isn't feasible. Plus things coded to use mouse events would then have to be recoded using touch events, and we don't really need multi-touch...)
Yes, I have attempted to simply turn off the touch-and-hold right click gesture. Unfortunately, doing so simply disables the drawing of a circle indicating a right click gesture around your finger and the fire of the subsequent right click. It does NOT remove the underlying problem: the delayed mouse down event for up to six seconds.
My Question: Is there a way to:
Ideally, indicate to Windows that my application is a touch-ready application, so it sends down events immediately (but, I suppose, still send mouse events instead of touch events)? I can see that the built-in soft keyboard works correctly, it seems. I just want my Java application to do the same.
Disable the delay entirely on the computer, but still provide basic touch functionality?
Potentially something as simple as this question, which seems to be asking about the same phenomenon, but in Java?
Typically this type of behavior is controlled by the touch device driver installed on the device. All of the touch manufacturers I have seen have control panel apps that allow you to customize touch behavior. So for instance you can tell the driver to send a mouse click immediately up receipt of a touch rather than delaying briefly in order to prevent an incidental touch from initiating an input event.
I want to create java code which will stimulate a mouse click on any window of a windows OS application - eg browser, word etc.
Can someone suggest how I can begin ? I don't know which API's are needed for this.
I also need to know if this is a very complex task and will require more than just
core concepts of Java.
Thanks in advance.
The class you would want to use for this task is the Robot class: http://docs.oracle.com/javase/7/docs/api/java/awt/Robot.html
It may require more knowledge than the core concepts (depending on what you consider core), but Java is a good language to deal with this kind of thing.
Depending on what you seek to do with this knowledge, this may end up a very complex task. For example, if you sought to click on a specific button on the screen, you would need some way to analyze the screen (a very hard task). If you know where every button is already, you just move to the x, y location and cause a click to occur.