FocusScope
The FocusScope
exposes callbacks to intercept key events. Note that FocusScope
will only invoke them when it has-focus
.
The KeyEvent has a text property, which is a character of the key entered. When a non-printable key is pressed, the character will be either a control character, or it will be mapped to a private unicode character. The mapping of these non-printable, special characters is available in the KeyEvent namespace
Properties
has-focus
bool (out)
default: false
Is true
when the element has keyboard focus.
enabled
bool default: true
When true, the FocusScope
will make itself the focused element when clicked. Set this to false if you don’t want the click-to-focus
behavior. Similarly, a disabled FocusScope
does not accept the focus via tab focus traversal. A parent FocusScope
will still receive key events from
child FocusScope
s that were rejected, even if enabled
is set to false.
Functions
focus()
Call this function to transfer keyboard focus to this FocusScope
, to receive future KeyEvents.
clear-focus()
Call this function to remove keyboard focus from this FocusScope
if it currently has the focus. See also FocusHandling.
Callbacks
key-pressed(KeyEvent) -> EventResult
Invoked when a key is pressed, the argument is a KeyEvent struct. The returned EventResult
indicates whether to accept or reject the event. Rejected events are forwarded to the parent element.
key-released(KeyEvent) -> EventResult
Invoked when a key is released, the argument is a KeyEvent struct. The returned EventResult
indicates whether to accept or reject the event. Rejected events are forwarded to the parent element.
focus-changed-event()
Invoked when the focus on the FocusScope
has changed.
© 2024 SixtyFPS GmbH