Results 1 to 5 of 5
Thread: outside hotkey
- 06-18-2010, 04:48 PM #1
outside hotkey
I want to get a key pressed outside of the frame. (hotkeys like "F1", "F2" ...)
get only the keys pressed inside of the JFrame.Java Code:import java.awt.event.KeyEvent; import java.awt.event.KeyListener; import javax.swing.JFrame; public class hotkey extends JFrame implements KeyListener { public hotkey() { addKeyListener(this); setSize(100, 100); setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); setVisible(true); } public void keyPressed(KeyEvent e) { if(e.getKeyCode() == KeyEvent.VK_F2) System.out.println("hotkey: F2, pressed"); } public void keyReleased(KeyEvent e) { } public void keyTyped(KeyEvent e) { } public static void main(String[] args) { new hotkey(); } }
Does someone know how its possible to get the keys pressed outside of the frame.
Thanks,
Dennis
- 06-18-2010, 05:14 PM #2
Does "outside" mean when another component has the focus?
Not sure that is possible. Sort of like listening to some one else's business that's none of yours.
- 06-18-2010, 06:44 PM #3
I mean with "outside" the frame: override [OS]-hotkey functions for use it in the java application.
- 06-18-2010, 07:25 PM #4
Does the frame have the focus?
- 06-18-2010, 07:37 PM #5
If you want it across the entire OS, then you will have to go down lower into JNI. Really, that kind of task would be better done in another language, as Java isn't designed to work at the low-levels.
One thing you can do is create C code and hook up your C code to your Java code through JNI. You can find tutorials on this which will tell you how you can do this.
Hope that helps :)http://www.tyroceur.co.cc ------ If my post was helpful, REP it ;)First, solve the problem. Then, write the code.
Similar Threads
-
How to add hotkey(Ctrl+VK) to a button?
By rpwtdj in forum Advanced JavaReplies: 5Last Post: 01-10-2008, 02:13 AM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks