I am playing around with javafx and am trying to add an EventHandler or EventFilter (not totally sure what the difference is right now) to one of my scenes. It should just detect any input, from mouse clicks to keys pressed.
I was able to write an EventFilter for mouse clicks but I cannot get it to work for any event in general.
My current idea was the following:
scene.addEventFilter(Event.ANY, new EventHandler<InputEvent>() {
@Override
public void handle(InputEvent event) {
System.out.println("Event detected! " + event.getSource());
}
});
But with this I get addEventFilter highlighted red with an error message like this:
The method addEventFilter(EventType<T>, EventHandler<? super T>) in the type Scene is not applicable for the arguments (EventType<Event>, new EventHandler<InputEvent>(){})
I am new to Java and I don't understand what to do. I wanted to catch input events within my scene but without the need of having a separate filter for every possible event.