How to use keyboard shortcuts outside a java application
Hi there. I know how to do keyboard shortcuts inside an application in java. The thing is, I can't figure how to add a keyboard shortcut outside of the application (let's say the platform would be Windows) to execute a specific block of code inside my application. I would like to use a keyboard shortcut (let's say CTRL+ALT+X or anything else that would be rarely used by other applications) to open up a small JDialog (I'm using swing components) in the application. The user would be able to use that shortcut anywhere in his windows platform.
Thanks a lot in advance. Refer me to any topics who have already talked about this situation because I couldn't find it anywhere on the web or post in if you got the answer. Thanks a lot!
[752 byte] By [
Ratiusa] at [2007-11-27 5:19:36]

Are you talking about a pure java application? If so, AFAIK, it can't be done. On the other hand, I'm sure it can be done w/ java and C++ or other language that can interface more directly with the operating system coupled by the JNI (which stands for, I believe, the java native interface).
Here is an article that delves into java keyboard hooks using the JNI and c#. The article is titled "[url=http://www.codeproject.com/useritems/javacsharp.asp]C# Method Calls Within Java Program[/url]".
If this is the route you wish to take, you may want to visit the [url=http://forum.java.sun.com/forum.jspa?forumID=52]Sun JNI forum[/url].
I am no expert in this (by any means), and I welcome smarter advice.
Good luck!
/Pete
If you are on a Windows box, create a bat file that executes your program. Create a shortcut on the desktop. Right click it, click Properties and edit the Shortcut Key.
> Are you talking about a pure java application? If
> so, AFAIK, it can't be done. On the other hand, I'm
> sure it can be done w/ java and C++ or other language
no it can't. How can your application define a keyboard shortcut outside its own context?
If that were possible a lot of other things would be possible, like one application telling another application what to do without that other application having an API to control it or your application using that API even if it existed.
What may be possible is for an application to use operating specific APIs to install hooks into the operating system. For example Windows has an API that allows you to add context menu entries through installing DLLs and adding references to them in the proper places in the registry.
But that's not the same.
> If you are on a Windows box, create a bat file that> executes your program. Create a shortcut on the> desktop. Right click it, click Properties and edit> the Shortcut Key.wow! Thinking outside the box... thanks!