Type KeyEvent
type KeyEvent struct {
Key Key
Modifiers Modifiers
Target ID
Repeat bool
// Release marks a key going up (see above).
Release bool
Text string
// Typed is the text a printable key types with the modifiers in effect,
// "A" for Shift+a, "!" for Shift+1 on a US layout, on the press of a
// terminal that asked for key releases (app.TextInput.KeyReleases). Text
// stays the character without modifiers and identifies the key. Typed is
// empty for a key that types nothing, for chords with Control, Command or
// Alt, and when the platform cannot say. A terminal that shows another
// machine's desktop uses it where the remote names characters.
Typed string
// Win32 is the console key record on Windows; other platforms leave it zero.
Win32 Win32Key
}KeyEvent is delivered to the currently focused hit target.
While a RoleTerminal hit has focus the keyboard is raw: printable characters and text-service input (input methods, dead keys, paste) arrive as text events (see app.TextInput), and every other key arrives here. Key names the navigation, editing and function keys; for a chord such as Ctrl+C, Key is KeyUnknown and Text holds the character without the modifiers applied ("c"). Text is otherwise empty on OnKey events. app.Config.OnShortcut separately receives modified printable chords before native text handling, except that a focused ordinary text field on Windows claims the standard editing chords.
A terminal that sets app.TextInput.KeyReleases gets the whole keyboard as presses and releases instead: every key that is not consumed by input-method composition arrives as a press (printable keys with Text, the character without modifiers, and Key KeyUnknown), a press that repeats has Repeat set, and the same Key and Text come back once with Release set when the key goes up, so the pair identifies the key even if the modifiers changed in between. Modifier keys are keys of their own then (KeyShiftLeft and so on). A release is never sent for a press the application did not receive, and every key still down when the terminal loses the keyboard, the window loses focus or the terminal stops asking is released first, so a remote never keeps a key. Handlers that did not ask for releases never see a Release event.