monomer-1.4.0.0: A GUI library for writing native Haskell applications.
Copyright(c) 2018 Francisco Vallarino
LicenseBSD-3-Clause (see the LICENSE file)
Maintainerfjvallarino@gmail.com
Stabilityexperimental
Portabilitynon-portable
Safe HaskellNone
LanguageHaskell2010

Monomer.Widgets.Containers.Keystroke

Description

Container which generates user provided events when combinations of keys occur. Using these event makes sense at the application or Composite level. If you are implementing a widget from scratch, keyboard events are directly available.

The shortcut definitions are provided as a list of tuples of Text, containing the key combination and associated event, separated by "-". The widget handles unordered combinations of multiple keys at the same time, but does not support ordered sequences (pressing "a", releasing, then "b" and "c"). The available keys are:

  • Mod keys: A, Alt, C, Ctrl, Cmd, O, Option, S, Shift
  • Action keys: Caps, Delete, Enter, Esc, Return, Space, Tab
  • Arrows: Up, Down, Left, Right
  • Function keys: F1-F12
  • Separator: Dash (since - is used for defining keystrokes)
  • Symbols: brackets, ^, *, &, etc.
  • Lowercase letters (uppercase keys are reserved for mod and action keys)
  • Numbers

The keys can be combined, for example:

  • Copy: "Ctrl-c" or "C-c"
  • App config: "Ctrl-Shift-p" or "C-S-p"
keystroke [(Esc, CancelEditing)] $ hstack [
    label "Username:",
    spacer,
    textField userLens
  ]

Note 1: Following the pattern explained in CmbIgnoreChildrenEvts, this widget by default allows children widgets (i.e., focused widgets) that may receive the events to respond to the pressed keys. If you want to avoid this, and only keep the keystroke widgets's response when a combination matches, add the ignoreChildrenEvts config option. To clarify: the only keypress event that will be filtered is the one that causes a combination to match (the last one).

Note 2: Except in the specific cases mentioned here (Ctrl, Cmd, etc), the keys must be single characters.

Note 3: Full words must be input exactly as indicated (Ctrl, Cmd, etc). Alias only exist for the keys described here (A for Alt, C for Ctrl/Cmd, etc).

Note 4: Symbols that require pressing the Shift key (^, &, etc) are virtual keys and share the KeyCode with the symbol associated to the same physical key. This causes issues when detecting their pressed status, and thus it's not possible to combine these symbols with letters, numbers or other symbols in the same keystroke. The same happens with characters that require pressing a combination of keys (e.g. accented characters). It is still possible to combine them with mod keys, so using "C-^" or "C-[" should work. If you find that binding a symbol/complex character does not work, try using the names of the physical keys instead (e.g. "Shift-e" instead of E).

Synopsis

Configuration

data KeystrokeCfg Source #

Configuration options for keystroke:

  • ignoreChildrenEvts: If True, when a shortcut is detected, the KeyAction event will not be passed down to children.

Constructors

keystroke :: WidgetEvent e => [(Text, e)] -> WidgetNode s e -> WidgetNode s e Source #

Creates a keystroke container with a single node as child.

keystroke_ :: WidgetEvent e => [(Text, e)] -> [KeystrokeCfg] -> WidgetNode s e -> WidgetNode s e Source #

Creates a keystroke container with a single node as child. Accepts config,