Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

HotKeys

 
Sam Benry
Ranch Hand
Posts: 89
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 32
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 89
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 3742
16
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Sam Benry
Ranch Hand
Posts: 89
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 32
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 89
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 32
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I cant remember anything for Ubuntu as of now. Let me try looking that up! Glad it helped
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic