Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions .changeset/dry-ducks-remain.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
"@interactors/globals": patch
"@interactors/keyboard": patch
---

Improve keyboard layout, by adding missing chars and fix pressing functional keys
2 changes: 1 addition & 1 deletion packages/globals/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
export * from './globals'
export { KeyboardLayout, KeyCode } from './keyboard-layout'
export * from './keyboard-layout'
372 changes: 369 additions & 3 deletions packages/globals/src/keyboard-layout.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,355 @@
// NOTE: List of keys from https://developer.mozilla.org/en-US/docs/Web/API/KeyboardEvent/key/Key_Values
export type KeyValue =
// Special keys
| 'Unidentified'
// Modifier keys
| 'Alt'
| 'AltGraph'
| 'CapsLock'
| 'Control'
| 'Fn'
| 'FnLock'
| 'Hyper'
| 'Meta'
| 'NumLock'
| 'ScrollLock'
| 'Shift'
| 'Super'
| 'Symbol'
| 'SymbolLock'
// Whitespace keys
| 'Enter'
| 'Tab'
| ' '
// Navigation keys
| 'ArrowDown'
| 'ArrowLeft'
| 'ArrowRight'
| 'ArrowUp'
| 'End'
| 'Home'
| 'PageDown'
| 'PageUp'
// Editing keys
| 'Backspace'
| 'Clear'
| 'Copy'
| 'CrSel'
| 'Cut'
| 'Delete'
| 'EraseEof'
| 'ExSel'
| 'Insert'
| 'Paste'
| 'Redo'
| 'Undo'
// UI keys
| 'Accept'
| 'Again'
| 'Attn'
| 'Cancel'
| 'ContextMenu'
| 'Escape'
| 'Execute'
| 'Find'
| 'Finish'
| 'Help'
| 'Pause'
| 'Play'
| 'Props'
| 'Select'
| 'ZoomIn'
| 'ZoomOut'
// Device keys
| 'BrightnessDown'
| 'BrightnessUp'
| 'Eject'
| 'LogOff'
| 'Power'
| 'PowerOff'
| 'PrintScreen'
| 'Hibernate'
| 'Standby'
| 'WakeUp'
// Common IME keys
| 'AllCandidates'
| 'Alphanumeric'
| 'CodeInput'
| 'Compose'
| 'Convert'
| 'Dead'
| 'FinalMode'
| 'GroupFirst'
| 'GroupLast'
| 'GroupNext'
| 'GroupPrevious'
| 'ModeChange'
| 'NextCandidate'
| 'NonConvert'
| 'PreviousCandidate'
| 'Process'
| 'SingleCandidate'
// Korean keyboards only
| 'HangulMode'
| 'HanjaMode'
| 'JunjaMode'
// Japanese keyboards only
| 'Eisu'
| 'Hankaku'
| 'Hiragana'
| 'HiraganaKatakana'
| 'KanaMode'
| 'KanjiMode'
| 'Katakana'
| 'Romaji'
| 'Zenkaku'
| 'ZenkakuHanaku'
// Function keys
| 'F1'
| 'F2'
| 'F3'
| 'F4'
| 'F5'
| 'F6'
| 'F7'
| 'F8'
| 'F9'
| 'F10'
| 'F11'
| 'F12'
| 'F13'
| 'F14'
| 'F15'
| 'F16'
| 'F17'
| 'F18'
| 'F19'
| 'F20'
| 'Soft1'
| 'Soft2'
| 'Soft3'
| 'Soft4'
// Phone keys
| 'AppSwitch'
| 'Call'
| 'Camera'
| 'CameraFocus'
| 'EndCall'
| 'GoBack'
| 'GoHome'
| 'HeadsetHook'
| 'LastNumberRedial'
| 'Notification'
| 'MannerMode'
| 'VoiceDial'
// Multimedia keys
| 'ChannelDown'
| 'ChannelUp'
| 'MediaFastForward'
| 'MediaPause'
| 'MediaPlay'
| 'MediaPlayPause'
| 'MediaRecord'
| 'MediaRewind'
| 'MediaStop'
| 'MediaTrackNext'
| 'MediaTrackPrevious'
// Audio control keys
| 'AudioBalanceLeft'
| 'AudioBalanceRight'
| 'AudioBassDown'
| 'AudioBassBoostDown'
| 'AudioBassBoostToggle'
| 'AudioBassBoostUp'
| 'AudioBassUp'
| 'AudioFaderFront'
| 'AudioFaderRear'
| 'AudioSurroundModeNext'
| 'AudioTrebleDown'
| 'AudioTrebleUp'
| 'AudioVolumeDown'
| 'AudioVolumeMute'
| 'AudioVolumeUp'
| 'MicrophoneToggle'
| 'MicrophoneVolumeDown'
| 'MicrophoneVolumeMute'
| 'MicrophoneVolumeUp'
// TV control keys
| 'TV'
| 'TV3DMode'
| 'TVAntennaCable'
| 'TVAudioDescription'
| 'TVAudioDescriptionMixDown'
| 'TVAudioDescriptionMixUp'
| 'TVContentsMenu'
| 'TVDataService'
| 'TVInput'
| 'TVInputComponent1'
| 'TVInputComponent2'
| 'TVInputComposite1'
| 'TVInputComposite2'
| 'TVInputHDMI1'
| 'TVInputHDMI2'
| 'TVInputHDMI3'
| 'TVInputHDMI4'
| 'TVInputVGA1'
| 'TVMediaContext'
| 'TVNetwork'
| 'TVNumberEntry'
| 'TVPower'
| 'TVRadioService'
| 'TVSatellite'
| 'TVSatelliteBS'
| 'TVSatelliteCS'
| 'TVSatelliteToggle'
| 'TVTerrestrialAnalog'
| 'TVTerrestrialDigital'
| 'TVTimer'
// Media controller keys
| 'AVRInput'
| 'AVRPower'
| 'ColorF0Red'
| 'ColorF1Green'
| 'ColorF2Yellow'
| 'ColorF3Blue'
| 'ColorF4Grey'
| 'ColorF5Brown'
| 'ClosedCaptionToggle'
| 'Dimmer'
| 'DisplaySwap'
| 'DVR'
| 'Exit'
| 'FavoriteClear0'
| 'FavoriteClear1'
| 'FavoriteClear2'
| 'FavoriteClear3'
| 'FavoriteRecall0'
| 'FavoriteRecall1'
| 'FavoriteRecall2'
| 'FavoriteRecall3'
| 'FavoriteStore0'
| 'FavoriteStore1'
| 'FavoriteStore2'
| 'FavoriteStore3'
| 'Guide'
| 'GuideNextDay'
| 'GuidePreviousDay'
| 'Info'
| 'InstantReplay'
| 'Link'
| 'ListProgram'
| 'LiveContent'
| 'Lock'
| 'MediaApps'
| 'MediaAudioTrack'
| 'MediaLast'
| 'MediaSkipBackward'
| 'MediaSkipForward'
| 'MediaStepBackward'
| 'MediaStepForward'
| 'MediaTopMenu'
| 'NavigateIn'
| 'NavigateNext'
| 'NavigateOut'
| 'NavigatePrevious'
| 'NextFavoriteChannel'
| 'NextUserProfile'
| 'OnDemand'
| 'Pairing'
| 'PinPDown'
| 'PinPMove'
| 'PinPToggle'
| 'PinPUp'
| 'PlaySpeedDown'
| 'PlaySpeedReset'
| 'PlaySpeedUp'
| 'RandomToggle'
| 'RcLowBattery'
| 'RecordSpeedNext'
| 'RfBypass'
| 'ScanChannelsToggle'
| 'ScreenModeNext'
| 'Settings'
| 'SplitScreenToggle'
| 'STBInput'
| 'STBPower'
| 'Subtitle'
| 'Teletext'
| 'VideoModeNext'
| 'Wink'
| 'ZoomToggle'
// Speech recognition keys
| 'SpeechCorrectionList'
| 'SpeechInputToggle'
// Document keys
| 'Close'
| 'New'
| 'Open'
| 'Print'
| 'Save'
| 'SpellCheck'
| 'MailForward'
| 'MailReply'
| 'MailSend'
// Application selector keys
| 'LaunchCalculator'
| 'LaunchCalendar'
| 'LaunchContacts'
| 'LaunchMail'
| 'LaunchMediaPlayer'
| 'LaunchMusicPlayer'
| 'LaunchMyComputer'
| 'LaunchPhone'
| 'LaunchScreenSaver'
| 'LaunchSpreadsheet'
| 'LaunchWebBrowser'
| 'LaunchWebCam'
| 'LaunchWordProcessor'
| 'LaunchApplication1'
| 'LaunchApplication2'
| 'LaunchApplication3'
| 'LaunchApplication4'
| 'LaunchApplication5'
| 'LaunchApplication6'
| 'LaunchApplication7'
| 'LaunchApplication8'
| 'LaunchApplication9'
| 'LaunchApplication10'
| 'LaunchApplication11'
| 'LaunchApplication12'
| 'LaunchApplication13'
| 'LaunchApplication14'
| 'LaunchApplication15'
| 'LaunchApplication16'
// Browser control keys
| 'BrowserBack'
| 'BrowserFavorites'
| 'BrowserForward'
| 'BrowserHome'
| 'BrowserRefresh'
| 'BrowserSearch'
| 'BrowserStop'
// Numeric keypad keys
| 'Decimal'
| 'Key11'
| 'Key12'
| 'Multiply'
| 'Add'
| 'Clear'
| 'Divide'
| 'Subtract'
| 'Separator'
| '0'
| '1'
| '2'
| '3'
| '4'
| '5'
| '6'
| '7'
| '8'
| '9'

export type KeyCode =
| "Backspace"
| "Tab"
Expand Down Expand Up @@ -99,11 +451,25 @@ export type KeyCode =
| "Slash"
| "Backquote"
| "BracketLeft"
| "Backslack"
| "Backslash"
Comment on lines 102 to +454
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🤣

| "BracketRight"
| "Quote";

interface CommonKey {
code: KeyCode;
key: string;
shiftKey?: true;
}

interface SpecialKey {
code: KeyCode;
key: KeyValue;
shiftKey?: true;
}

export type Key = CommonKey | SpecialKey

export interface KeyboardLayout {
getKey(code: KeyCode): string | undefined;
getCode(key: string): KeyCode | undefined;
getByCode(code: KeyCode): Key | undefined;
getByKey(key: string): Key | undefined;
}
Loading