Results 1 to 5 of 5

Thread: outside hotkey

  1. #1
    Dennis's Avatar
    Dennis is offline Member
    Join Date
    May 2010
    Posts
    83
    Rep Power
    0

    Default outside hotkey

    I want to get a key pressed outside of the frame. (hotkeys like "F1", "F2" ...)

    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();
    	}
    }
    get only the keys pressed inside of the JFrame.

    Does someone know how its possible to get the keys pressed outside of the frame.

    Thanks,
    Dennis

  2. #2
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    17,616
    Rep Power
    25

    Default

    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.

  3. #3
    Dennis's Avatar
    Dennis is offline Member
    Join Date
    May 2010
    Posts
    83
    Rep Power
    0

    Default

    I mean with "outside" the frame: override [OS]-hotkey functions for use it in the java application.

  4. #4
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    17,616
    Rep Power
    25

    Default

    Does the frame have the focus?

  5. #5
    tyroceur's Avatar
    tyroceur is offline Member
    Join Date
    May 2010
    Location
    Fast Growing City, INDIA
    Posts
    44
    Rep Power
    0

    Default

    Quote Originally Posted by Dennis View Post
    I mean with "outside" the frame: override [OS]-hotkey functions for use it in the java application.
    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 :)
    First, solve the problem. Then, write the code.
    http://www.tyroceur.co.cc ------ If my post was helpful, REP it ;)

Similar Threads

  1. How to add hotkey(Ctrl+VK) to a button?
    By rpwtdj in forum Advanced Java
    Replies: 5
    Last Post: 01-10-2008, 03:13 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •