Skip to main content

Overview

The key mapping system provides a comprehensive mapping table between keyboard key names and their corresponding keycodes. This is essential for handling keyboard shortcuts and events in AppFlowy Editor.

keyToCodeMapping

Map<String, int> keyToCodeMapping
A map that translates keyboard key labels (strings) to their hexadecimal keycodes (integers). All keys are stored in lowercase. Source: Copied from Flutter project’s keyboard_key.dart.

Key Categories

Printable Characters

Basic Characters

'space': 0x00000000020,
'exclamation': 0x00000000021,
'quote': 0x00000000022,
'number sign': 0x00000000023,
'dollar': 0x00000000024,
'percent': 0x00000000025,
'ampersand': 0x00000000026,
'quote single': 0x00000000027,

Digits

'digit 0': 0x00000000030,
'digit 1': 0x00000000031,
'digit 2': 0x00000000032,
// ... through digit 9

Letters (A-Z)

'a': 0x00000000061,
'b': 0x00000000062,
'c': 0x00000000063,
// ... through z

Punctuation

'comma': 0x0000000002c,
'period': 0x0000000002e,
'slash': 0x0000000002f,
'semicolon': 0x0000000003b,
'bracket left': 0x0000000005b,
'bracket right': 0x0000000005d,
'backslash': 0x0000000005c,
'backquote': 0x00000000060,

Control Keys

'backspace': 0x00100000008,
'tab': 0x00100000009,
'enter': 0x0010000000d,
'escape': 0x0010000001b,
'delete': 0x0010000007f,

Modifier Keys

'control': 0x002000001f0,
'shift': 0x002000001f2,
'alt': 0x002000001f4,
'meta': 0x002000001f6,
'control left': 0x00200000100,
'control right': 0x00200000101,
'shift left': 0x00200000102,
'shift right': 0x00200000103,
'alt left': 0x00200000104,
'alt right': 0x00200000105,
'meta left': 0x00200000106,
'meta right': 0x00200000107,

Arrow Keys

'arrow down': 0x00100000301,
'arrow left': 0x00100000302,
'arrow right': 0x00100000303,
'arrow up': 0x00100000304,
'home': 0x00100000306,
'end': 0x00100000305,
'page up': 0x00100000308,
'page down': 0x00100000307,

Function Keys

'f1': 0x00100000801,
'f2': 0x00100000802,
'f3': 0x00100000803,
// ... through F24
'f12': 0x0010000080c,
'f24': 0x00100000818,

Numpad Keys

'numpad 0': 0x00200000230,
'numpad 1': 0x00200000231,
// ... through numpad 9
'numpad enter': 0x0020000020d,
'numpad add': 0x0020000022b,
'numpad subtract': 0x0020000022d,
'numpad multiply': 0x0020000022a,
'numpad divide': 0x0020000022f,
'numpad decimal': 0x0020000022e,

Special Lock Keys

'caps lock': 0x00100000104,
'num lock': 0x0010000010a,
'scroll lock': 0x0010000010c,

Media Keys

'media play pause': 0x00100000a05,
'media stop': 0x00100000a07,
'media track next': 0x00100000a08,
'media track previous': 0x00100000a09,
'audio volume down': 0x00100000a0f,
'audio volume up': 0x00100000a10,
'audio volume mute': 0x00100000a11,

System Keys

'print screen': 0x00100000608,
'pause': 0x00100000509,
'insert': 0x00100000407,
'help': 0x00100000508,

Editing Keys

'copy': 0x00100000402,
'cut': 0x00100000404,
'paste': 0x00100000408,
'undo': 0x0010000040a,
'redo': 0x00100000409,
'select': 0x0010000050c,
'find': 0x00100000507,

Browser Keys

'browser back': 0x00100000c01,
'browser forward': 0x00100000c03,
'browser refresh': 0x00100000c05,
'browser home': 0x00100000c04,
'browser search': 0x00100000c06,
'browser favorites': 0x00100000c02,
'browser stop': 0x00100000c07,

Application Launch Keys

'launch mail': 0x00100000b03,
'launch media player': 0x00100000b04,
'launch web browser': 0x00100000b09,
'launch calculator': 0x00100000b01, // Launch Application 1
'launch contacts': 0x00100000b0c,

Usage

Looking Up a Keycode

import 'package:appflowy_editor/src/service/shortcut_event/key_mapping.dart';

// Get keycode for a specific key
final enterKeyCode = keyToCodeMapping['enter'];
print(enterKeyCode); // 0x0010000000d

// Get keycode for a letter
final aKeyCode = keyToCodeMapping['a'];
print(aKeyCode); // 0x00000000061

Case Insensitivity

All keys in the map are lowercase:
// Correct
final code = keyToCodeMapping['a'];

// Won't work - keys are lowercase
final wrongCode = keyToCodeMapping['A']; // null

// Always convert to lowercase
final safeCode = keyToCodeMapping['A'.toLowerCase()];

Using with Keybinding

The Keybinding class uses this mapping internally:
class Keybinding {
  final String keyLabel;
  
  int get keyCode => keyToCodeMapping[keyLabel.toLowerCase()]!;
}

Checking Available Keys

// Get all available keys
final availableKeys = keyToCodeMapping.keys.toList();
print('Total keys: ${availableKeys.length}');

// Check if a key is supported
if (keyToCodeMapping.containsKey('space')) {
  print('Space key is supported');
}

Common Key Lookups

// Frequently used keys
final commonKeys = {
  'Space': keyToCodeMapping['space'],
  'Enter': keyToCodeMapping['enter'],
  'Backspace': keyToCodeMapping['backspace'],
  'Delete': keyToCodeMapping['delete'],
  'Tab': keyToCodeMapping['tab'],
  'Escape': keyToCodeMapping['escape'],
};

// Arrow keys
final arrowKeys = {
  'Up': keyToCodeMapping['arrow up'],
  'Down': keyToCodeMapping['arrow down'],
  'Left': keyToCodeMapping['arrow left'],
  'Right': keyToCodeMapping['arrow right'],
};

// Modifier keys
final modifiers = {
  'Control': keyToCodeMapping['control'],
  'Shift': keyToCodeMapping['shift'],
  'Alt': keyToCodeMapping['alt'],
  'Meta': keyToCodeMapping['meta'],
};

Complete Key List

The mapping includes over 400 keys covering:
  • Printable characters - Letters, digits, punctuation, symbols
  • Control keys - Enter, Tab, Escape, Backspace, Delete
  • Modifier keys - Ctrl, Shift, Alt, Meta/Command (including left/right variants)
  • Navigation keys - Arrows, Home, End, Page Up/Down
  • Function keys - F1-F24
  • Numpad keys - 0-9 and operators
  • Lock keys - Caps Lock, Num Lock, Scroll Lock
  • Media keys - Play, Pause, Volume, etc.
  • System keys - Print Screen, Pause, Insert
  • Editing keys - Copy, Cut, Paste, Undo, Redo
  • Browser keys - Back, Forward, Refresh, Home
  • Application launch keys - Mail, Browser, Calculator, etc.
  • TV/Remote control keys - Channel, Input, Guide, etc.
  • Game controller keys - Buttons, triggers, thumbsticks
  • International keys - Language-specific input keys

Important Notes

All key labels in the mapping are lowercase. Always convert input to lowercase before lookup.
The mapping is based on Flutter’s LogicalKeyboardKey keycodes. The hexadecimal values match Flutter’s keyboard key system.
For compound keys (like ‘digit 1’ or ‘arrow up’), use the full label exactly as shown in the mapping.

Extending the Mapping

While the default mapping is comprehensive, you can extend it if needed:
// Add custom key mappings
keyToCodeMapping['custom_key'] = 0x00300000001;

// Or create your own map
final customKeyMap = {
  ...keyToCodeMapping,
  'special_key': 0x00400000001,
};

See Also

Build docs developers (and LLMs) love