I'm creating a program which lets the user define buttons, which then will fire notes to the synthesizer. Make your own, custom keyboard of sorts.
Now this keyboard should also react to global, custom hotkeys.
And here lies the problem: To make them global, I attach them to the scene, but then every newly set hotkey overwrites the previous ones. Have some code:
btn.getScene().setOnKeyPressed((KeyEvent e) -> {
if (e.getText().equals(hotkey)) {
btn.arm();
btn.fire();
}
});
btn.getScene().setOnKeyReleased((KeyEvent e) -> {
if (e.getText().equals(hotkey)) {
btn.disarm();
}
});
The immediate solution that comes to mind is creating an arraylist that keeps track of all the hotkeys, and have the keylistener iterate over it every time, and another arraylist of arraylists with the associating buttons.
Is there maybe a more elegant, direct way?