FocusScope
export component Example inherits Window { width: 100px; height: 100px; forward-focus: my-key-handler; my-key-handler := FocusScope { key-pressed(event) => { debug(event.text); if (event.modifiers.control) { debug("control was pressed during this event"); } if (event.text == Key.Escape) { debug("Esc key was pressed") } accept } }}
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
Section titled “Properties”has-focus
Section titled “has-focus” bool (out)
default: false
Is true
when the element has keyboard focus.
enabled
Section titled “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
Section titled “Functions”focus()
Section titled “focus()”Call this function to transfer keyboard focus to this FocusScope
, to receive future KeyEvents.
clear-focus()
Section titled “clear-focus()”Call this function to remove keyboard focus from this FocusScope
if it currently has the focus. See also FocusHandling.
Callbacks
Section titled “Callbacks”key-pressed(KeyEvent) -> EventResult
Section titled “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
Section titled “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()
Section titled “focus-changed-event()”Invoked when the focus on the FocusScope
has changed.
© 2025 SixtyFPS GmbH