This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
The moose likes Java in General and the fly likes HotKeys Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "HotKeys" Watch "HotKeys" New topic
Author

HotKeys

Sam Benry
Ranch Hand

Joined: Mar 21, 2008
Posts: 89
I googled and googled and I can't seem to find anything, how can I assign a hot key in Java?
For example, when Tab(or F12) is pressed Print Something to the Terminal ....
Prakash Subramanian
Ranch Hand

Joined: Feb 03, 2005
Posts: 32
If you are developing a Swing application, you can use the setMnemonic(int) API's in JButton and similar components. If you are looking for a general solution, I guess you have to implement your own solution. I am not aware of a general solution for that.
Sam Benry
Ranch Hand

Joined: Mar 21, 2008
Posts: 89
Swing application means a Form ? Thats not what I want, I want to assign a hot key, in other words, whenever this key is pressed, and who ever has the focus (java application will probably not have focus), when ever the key is pressed a certain action will occur.
I already was able to do this using Visual Basic.Net and Delphi, so I am assuming there must be a way to do this using java... I just can't seem to find any..
Joanne Neal
Rancher

Joined: Aug 05, 2005
Posts: 3432
    
  12
Originally posted by Sam Benry:
so I am assuming there must be a way to do this using java... I just can't seem to find any..


Unlikely. I'm fairly sure Java programs only pick up key presses when they have the focus. VB.Net and Delphi are probably using Windows APIs which you can do from Java using JNI, but this will mean your program will no longer be platform independent.


Joanne
Sam Benry
Ranch Hand

Joined: Mar 21, 2008
Posts: 89
So I'd have to program 2 applications, 1 for Windows and 1 for Linux ? (If I want to use it on Windows and Linux)

I've heard that programming with JNI is pretty complicated, is that true?
Prakash Subramanian
Ranch Hand

Joined: Feb 03, 2005
Posts: 32
Well platform dependency means you would have to maintain multiple versions of your software. Your task will be made easier if you can use a portable library, but I guess you would have to look that up.

The complexity of JNI depends on your native code too. JNI by itself is okay, but depending on your requirements you might have to use it in complex ways

There is a library for Windows, which can do your job... Try http://melloware.com/products/jintellitype/index.html

For other platforms, let me try looking up... Hope the above helps!
Sam Benry
Ranch Hand

Joined: Mar 21, 2008
Posts: 89
thank you Prakash, that link was very usefull.. Do you know a similar one for registing hot keys on Linux (Ubuntu) ?

thanks a million.
Prakash Subramanian
Ranch Hand

Joined: Feb 03, 2005
Posts: 32
I cant remember anything for Ubuntu as of now. Let me try looking that up! Glad it helped
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: HotKeys
 
Similar Threads
XSD - restrctions/enumeration - Only Weekdays
Simplex Algortithm implementation
why we get away with this?
Matrix Revolutions And Religion
[MySQL] Connection reset by peer: socket write error