2016-09-21 136 views
1

我正在嘗試構建視頻播放器。在這我想尋求媒體使用CtrlLEFTRIGHT鍵。JavaFX KeyCodeCombination Control + LEFT或Ctrl + RIGHT鍵

我試過兩種方式:

KeyCombination.keyCombination("Ctrl+RIGHT").match(e); 

KeyCodeCombination(KeyCode.LEFT, KeyCombination.CONTROL_DOWN).match(e); 

其他鍵組合工作,但這些都沒有。

有什麼辦法可以實現嗎?

回答

1

您可以嘗試使用SHORTCUT_DOWN而不是CONTROL_DOWN,因爲第一個平臺是獨立的。

返回此事件中主機平臺公用捷徑修飾符是否爲 。這個通用的快捷鍵修飾符是一個修飾鍵 ,通常在主機平臺的快捷鍵中使用。它適用於Windows上的 示例控件和Mac上的meta(命令鍵)。

然後你有這樣幾個機會:

node.setOnKeyPressed(e -> { 
    if (new KeyCodeCombination(KeyCode.LEFT, KeyCombination.SHORTCUT_DOWN).match(e)) { 
     // ... 
    } 
}); 

node.setOnKeyPressed(e -> { 
    if (e.getCode() == KeyCode.LEFT && e.isShortcutDown()) { 
     // ... 
    } 
}); 
+0

是的,我可以用,但我不想。我特別想使用'Control + LEFT'。您可以在VLC Player和KMPlayer上看到用戶可以使用這些組合鍵來查找媒體。 順便問一下,你能告訴我哪一個是快捷鍵嗎?我試圖使用您提供的組合鍵,但我無法實現。我正在使用Windows 8.1操作系統。 –

+0

快捷方式是Windows上的控制鍵。你現在可以發佈你的?幫助會容易得多。 – DVarga

+0

這是 - '如果(keyCombinationControlRight.match(E)||新KeyCodeCombination(KeyCode.RIGHT,KeyCombination.SHORTCUT_DOWN).match(E)){ \t \t \t \t通信System.err.println(「CTRL + RIGHT 「); (newPost.getCurrentTime()。toMillis()+ longSeekTime.toMillis())); \t \t \t} \t \t \t否則,如果(keyCombinationControlLeft.match(E)||新KeyCodeCombination(KeyCode.LEFT,KeyCombination.SHORTCUT_DOWN).match(E)) \t \t \t { \t \t \t \t System.err的.println( 「CTRL + LEFT」); ());}};}}};}}};}}};}} mediaPlayer.seek(newPeerPlayer.getCurrentTime()。toMillis() - longSeekTime.toMillis())); \t \t \t} ' –