2012-03-23 4 views
0

に私はプログラムを持っていないとき:JAVA:HKと実行プログラムの焦点

`

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); 
    } 
} 

`

i "がVK_NUMPAD0" タイマーのようなキーボードのキーを押すべきカウントダウンを開始する。私はそれをカウントダウンするクラスを持っています。

私の質問は:フレームがでなく、キーボードのプッシュを聞くにはどうすればいいですか?にフォーカスがあります。それはちょうど上に横たわるだろうから。

答えて

0

できません。 JNIを使​​用してより深い作業フックを書くことは可能ですが、ちょっと残酷です。

EDIT:すべてのキーボードイベントを取得するには100%透過型フルスクリーンウィンドウ(http://java.sun.com/developer/technicalArticles/GUI/translucent_shaped_windows/)を使用しないでください(ウィンドウを完全に透明にするとキーイベントを受け取ることはできません)。それは達成するのが難しいです。

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

関連する問題