Closed Clashsoft closed 8 months ago
I like the idea, this would certainly remove a lot of boilerplate code. However, I got a few questions:
@onKey
to @onEvent
and back. What exactly should be the name and therefore the functionality?text
and character
for if there already is code
?KeyEvent.KEY_PRESSED
cannot be used inside of annotations as it is not a constant. This could be solved by creating an own enum instead which then internally references the event or by using the event nameI changed it to @OnKey
everywhere. The different key event types would need to be an enum. But there are only a few cases so it should be ok. Example:
@interface OnKey {
enum Type { ANY, PRESSED, RELEASED, TYPED };
Type type() = PRESSED;
}
Is your feature request related to a problem? Please describe. Some apps require keyboard shortcuts that cannot be reasonably attached to a node. Usually that is because the node in question is not focusable. An annotation to create global key listeners (as implemented below) would be helpful.
Describe the solution you'd like
Describe alternatives you've considered
Detailed description The
@OnKey
annotation could be defined like this:The method should optionally allow a
KeyEvent
parameter (just like methods called from FXML). It could be used to inspect the event in case the KeyCode is dynamic/configurable.