Hi,
I have one question. You know some applications can be minimized to the lower right corner and with a hot key (e.g. ctrl+F1). Once the hot key is pressed, the application is activated or some event is activated. I wonder how to do that in java if there is any way. If you know, please give a very simple example. Thanks.

Hi,
I have one question. You know some applications can be minimized to the lower right corner and with a hot key (e.g. ctrl+F1). Once the hot key is pressed, the application is activated or some event is activated. I wonder how to do that in java if there is any way. If you know, please give a very simple example. Thanks.

Set up a Key Listener and have that Key Listener look out for that Hot Key and then do whatever (in your case, minimize)? Notsure if that's what you have in mind.

http://java.sun.com/docs/books/tutorial/uiswing/events/keylistener.html

If you're asking about how to bring UP a window or do something when a hotkey is pressed, it would involve making an invisible Window that's always on top of everything else, and adding a key listener to that. (I think that would work, I haven't tried it, but I want to XD)

thank you for the response but that is not what i am looking for. I think I did not express clearly enough. My goal was actually to creat a tray icon and set up a global hotkey. However, after days of searching, I found out that this is not trivial with Java because the use of key listener needs the "key board focus". I do not want it to steal the focus when I am doing something else. Realisation of global hotkey must involve JNI to call a C program, in which I do not have that patience and interest. Sorry for bothering you guys with this tricky quetion.

That's alright. you can still make a tray icon, in Java 1.6, there is a SystemTray class that can add an icon to the tray, and you don't have to mess with JNI (YAY!)

That's alright. you can still make a tray icon, in Java 1.6, there is a SystemTray class that can add an icon to the tray, and you don't have to mess with JNI (YAY!)

As I said, this is not a problem of tray icon which can be very easily created. It is about using the hot key without keyboard focus

Why not use the windows shortcut hotkey to run your java program? All you have to do is create a shortcut and define it a hotkey which will cause it to start. You can have your app automatically close when its finished doing whatever it has to do. To run it again, you would just do the hotkey again.

I don't know about Java but I prefer using AutoHotKey for such purposes. Have a look at it.

This question has already been answered. Start a new discussion instead.