KeyBinding class

Key bindings associate key names with Command-style functions.

Key names may be strings like "Shift-Ctrl-Enter"—a key identifier prefixed with zero or more modifiers. Key identifiers are based on the strings from Flutter's LogicalKeyboardKey.keyLabel.

Modifiers can be given in any order:

  • Shift- (or s-)
  • Alt- (or a-)
  • Ctrl- (or c- or Control-)
  • Cmd- (or m- or Meta-)

When a key binding contains multiple key names separated by spaces, it represents a multi-stroke binding, which will fire when the user presses the given keys after each other.

You can use Mod- as a shorthand for Cmd- on Mac and Ctrl- on other platforms. So Mod-b is Ctrl-b on Linux but Cmd-b on macOS.

Example:

KeyBinding(
  key: 'Mod-s',
  run: (view) {
    saveDocument();
    return true;
  },
)

Constructors

KeyBinding({String? key, String? mac, String? win, String? linux, Command? run, Command? shift, bool any(dynamic view, KeyEvent event)?, String? scope, bool preventDefault = false, bool stopPropagation = false})
const

Properties

any → bool Function(dynamic view, KeyEvent event)?
When this property is present, the function is called for every key that is not a multi-stroke prefix.
final
hashCode → int
The hash code for this object.
no setterinherited
key → String?
The key name to use for this binding.
final
linux → String?
Key to use specifically on Linux.
final
mac → String?
Key to use specifically on macOS.
final
platformKey → String?
Get the appropriate key for the current platform.
no setter
preventDefault → bool
When set to true (the default is false), this will always prevent the further handling for the bound key, even if the command(s) return false.
final
run → Command?
The command to execute when this binding is triggered.
final
runtimeType → Type
A representation of the runtime type of the object.
no setterinherited
scope → String?
By default, key bindings apply when focus is on the editor content (the "editor" scope).
final
shift → Command?
When given, this defines a second binding, using the (possibly platform-specific) key name prefixed with Shift- to activate this command.
final
stopPropagation → bool
When set to true, stopPropagation will be called on keyboard events that have their preventDefault called in response to this key binding.
final
win → String?
Key to use specifically on Windows.
final

Methods

noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
toString() → String
A string representation of this object.
inherited

Operators

operator ==(Object other) → bool
The equality operator.
inherited