Keyboard events

Two kinds of keyboard events can be generated for a View that has received input focus.

Event Constant Description
"key-down-event" KeyDownEvent The key has been pressed.
"key-up-event" KeyUpEvent The key has been released.

The main event data listener has the following format:

func(View, KeyEvent)

where the second argument describes the parameters of the keys pressed. The KeyEvent structure has the following fields:
Field Type Description
TimeStamp uint64 The time the event was created (in milliseconds). The starting point depends on the browser implementation (EPOCH, browser launch, etc.).
Key string The value of the key on which the event occurred. The value is returned taking into account the current language and case.
Code string The key code of the represented event. The value is independent of the current language and case.
Repeat bool Repeated pressing: the key was pressed until its input began to be automatically repeated.
CtrlKey bool The Ctrl key was active when the event occurred.
ShiftKey bool The Shift key was active when the event occurred.
AltKey bool The Alt (Option or ⌥ in OS X) key was active when the event occurred.
MetaKey bool The Meta key (for Mac, this is the ⌘ Command key; for Windows, the Windows key ⊞) was active when the event occurred.

You can also use listeners in the following formats:

  • func(KeyEvent)
  • func(View)
  • func()

You can get lists of listeners for keyboard events using the functions:

func GetKeyDownListeners(view View, subviewID ...string) []func(View, KeyEvent)
func GetKeyUpListeners(view View, subviewID ...string) []func(View, KeyEvent)