Hi,
I wish to listen for a keydown even, for whenever my utility window is in focus
I expected this to work:
root.RegisterCallback<KeyDownEvent>(MyCallback);
However MyCallback never gets called*, I have tried on trickle down and bubble up
*Every now and again it will get called but I can not find a repo, it may be alt-tabbing into unity.
Thanks in advance
Keyboard are only sent to the target that has the keyboard focus. To be able to receive the keyboard focus, the visualElement must be “focusable=true”. If root is not focusable or if no descendant of it is focusable, then these events will never be sent.
Once an element is focusable, it will receive focus when clicked, or cycled with tab presses, only then KeyEvents will be sent to it and can be caught by the register callback at the root.
Hope that helps,
1 Like
Hi
Yes thank you I was missing the focusable tag however from what you said, maybe I should not be doing it this way?
I want to listen to the arrow keys to allow the user to navigate the window (think ListView pressing down moves to the next item)
curiously, even before I added focusable, I am able to recieve click events