Windows Event handing in Java - java

I am a newbie to Java and I'd like to know how to handle Windows' events in Java. To be specific, I'd like to know how to handle events such as mouse moved or mouse clicked in Windows XP and Windows Vista. I want to wire my own custom behavior in my application to these events, even when my application is inactive or otherwise hidden.

Check this out: Implementing Listeners for Commonly Handled Events.

Related

Multi-touch events in Java on Linux: events from OS or recognize in application?

I'm trying to implement an JavaFX application which is able to make use of touch events and multi-touch gestures. I'm working with Java8 on Linux Mint 17.
I'm using a touch foil as input device. It's eGalaxTouch device (PCAP7200 series) using an EETI eGTouch driver (eGTouchD version: 2.5). It's recognized as standard mouse input device but also creates multi-touch events (ABS_MT_SLOT, ABS_MT_TRACKING_ID, ABS_MT_POSITION_X, ABS_MT_POSITION_Y) which can be read from /dev/input/eventX.
Ubuntu now comes with some multi-touch support and is able to recognize gestures. Is it possible to use those OS generated events in my application and to listen to them like to mouse events with a MouseListener?
Or do I have to recognize gestures in my application, possibly with the help of a library like MT4J?
Since I just started to get acquainted with this stuff, I appreciate any hint or help.
I haven't tried yet, but note that JavaFX also supports GestureEvents such as RotateEvent, ScrollEvent, SwipeEvent, ZoomEvent and probably(?) also custom events.
http://docs.oracle.com/javase/8/javafx/api/javafx/scene/input/package-summary.html

java.awt.Robot: how to send mouse/keyboard events to a specific window? with cross-platform support?

So from this question In Java Swing how do you get a Win32 window handle (hwnd) reference to a window? it appears that I can get the window32 handle .
would it be possible for java.awt.Robot to send mouse/keyboard events to that window handle?
sometimes when I am sending keys via Robot, if the window gets minimized, it will start typing into other background irrelevant windows that are open. I want to prevent this by allowing Robot to send keys and mouse events to that specific window of interest.
Would it be possible to achieve the same deal in Mac and Linux as well? be able to send Robot events to those respective specific window handles?
This is a classic problem with Robot. As they have quoted in the other thread, its not possible with pure AWT/Swing. You have to get into sun's internal API or use native code. There is not getting around that problem.
It is exactly because of the problem that you have i.e. make it work across OS's is why Java has not exposed such a control.
It would be useful to know what you are using this for.

Will a native GUI based desktop application respond to touch events on a tablet?

I have never worked on android before and hence I am presuming that implementing touch/mouse events for a tablet/mobile application might slightly be different compared to events triggered in GUI components of native programming languages.
This question is not related to Android though. If I completely remove all traces of Android OS from a tablet, load and mount it with just a Linux kernel with jvm/jre installed, and few jars that launch a custom java GUI application i.e in such a way that the tablet boots and starts with the custom java application by default, Will this native swing based desktop application respond to mouse events triggered by touch? If yes, is it as good as that in Android?
PS: Precisely, With more emphasis on mouse click, mouse entered and mouse exited events..

Kiosk mode for Linux Java Swing application

How can I disable OS-level keyboard shortcuts (e.g. Alt-Tab, Ctrl-Alt-Left/Right, etc.) on a [Ubuntu] Linux machine? I'm developing a full-screen Java Swing app and don't want the user to be able to task switch away from the program arbitrarily. It's not enough to toggle the "always on top" flag; users mustn't be allowed to switch workspaces, migrate focus or any other such things. The machine must function normally before and after the application is executed. Google says that this will require JNI or JNA but I'm looking for a bit more hand-holding.
There's no point in trying to do this in your application because any of these changes are going to need to be handled by X11 and/or the window manager since those are what respond to the commands. Assuming that you have control of the platform, choose a window manager which supports a kiosk mode. Then use the window manager's settings to start your application and enter kiosk mode.
Options for window managers which can do this include KDE or twm-kiosk.
(And if you don't have control of the platform, you're not likely to be able to have your application intercept things like ctrl-alt-backspace anyway.)
Edit:
In response to a scaled-down version of the question in which he's willing to let things like ctl-alt-backspace go and just wants most of the keys including alt-tab or other similar application switching key combinations, the following should work:
You should be able to do this using XLib's XGrabKeyboard method through JNI. This Java/XLib JNI keypress capture tutorial should be a good starting point. However, it uses XGrabKey which just passively listens for keys and does not prevent other applications from receiving them. You'll instead want to use XGrabKeyboard which actively snags all of the normal keyboard events (which, if the premise of this StackOverflow question is correct, includes the task switching keys).
Note that as a side-effect, key capture in Swing will also probably stop working because your Swing windows are going to be separate from the window you create in C. As such, you will probably have to use your JNI interface to get key presses to your program when needed. (Although I would definitely advise testing it first before writing the code.) You might be able to avoid this if you can get the window using Java AWT Native Interface to get the window ID. (Note that Swing is built on top of AWT, so this will work for Swing.) However, I'm not sure how to do this. It looks like you might be able to navigate the window tree by getting the root window from the Display and going from there to find your Window, but it's all kind of weird. It would be nice if the AWT NI just told you the window ID, but it doesn't look like it does that.
As this warning Reminder: XGrabKeyboard is not a security interface notes, this doesn't make it impossible for other programs to see the keys, but it seems likely that window managers will not be using XQueryKeyMap so it is likely to prevent task switching.

Mac OSX Java: Receive mouse events when not activated

I am writing a Java Swing application that needs to have a window receive mouse movement events when the application is not activated - think of it like a global always-on-top toolbar that animates when the mouse passes over it.
From my research so far, I have seen that the Mac Java JRE only passes events when the application has focus.
It does not appear to be a limitation of the OS, so I was hoping that there was a system property, an application package property or a system call that enabled non-activated event handling. Failing that, some method of globally capturing mouse movement events and passing them in to the Java application.
Thanks for any suggestions...
Edit: One further question: Once mouse move events have been captured, how do you feed them into Swing so that they are treated in the same was as native OS mouse events -- by finding the component under the mouse and sending a MouseEvent to it...
This isn't possible with pure Java.
You will need JNI and to write a global keylistener (or a keyboard hook) in C++ or another language.
Here are some topics about Global KeyListener:
Coderanch.
My own topic on Stack Overflow
Stack Overflow
Keyboard hooks in Mac OS X
On the last topic: this was a given solution for OSX.

Categories