0

I have the program:

`

import java.awt.FlowLayout;
import javax.swing.JFrame;
import javax.swing.JLabel;

public class Main {
    public static void main(String[] args) {
        JLabel time = new JLabel("10");
    JLabel timer = new JLabel("Timer: ");

    JFrame frame = new JFrame("Timer");
    frame.setLayout(new FlowLayout());
    frame.add(timer);
    frame.add(time);
    frame.pack();
        frame.setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
    frame.setLocationByPlatform( true );
    // Set's the window to be "always on top"
    frame.setAlwaysOnTop( true );
    frame.setVisible(true); 
    }
}

`

When i push a key on the keyboard like "VK_NUMPAD0" the timer should start count down. I have a class that make it count down.

My Question is: How can I listen to the keyboard push when the frame is not in focus. Since it will just be laying on the top.

NeFaX
  • 1

1 Answers1

0

You can't. Using JNI to write a deeper working hook is possible but kinda overkill.

EDIT: Well, you might try to use not a 100% transluent full screen window (http://java.sun.com/developer/technicalArticles/GUI/translucent_shaped_windows/) to get all the keyboard events (making the window fully transluent wouldn't allow you to receive key events), but other than that, its hardly to achieve.

P.P.S: Java System-Wide Keyboard Shortcut

Community
  • 1
  • 1
lzdt
  • 489
  • 1
  • 6
  • 17