Skip to main content
docs/guides/hardware-keyboard

Hardware keyboard

The keys CodePad handles on each platform, and how to drive the same table from JavaScript.

Edit this page

CodePad handles the keys in the following table on any hardware keyboard, whether it's a Bluetooth or USB keyboard, a Chromebook, an iPad keyboard, or the Mac keyboard on the simulator. Every other key goes to the platform. Letters and symbols type like the soft keyboard: brackets close on their own, and typing groups into one undo step.

ActionAndroidiOS
Move by one character, where an emoji counts as oneLeft, RightLeft, Right
Move by one wordCtrl+Left, Ctrl+RightOption+Left, Option+Right
Move up or down one row, back to the same column after a shorter lineUp, DownUp, Down
Move by one screen of textPage Up, Page DownPage Up, Page Down
Line start, line endHome, EndHome, End, Cmd+Left, Cmd+Right
Document start, document endCtrl+Home, Ctrl+EndCmd+Home, Cmd+End, Cmd+Up, Cmd+Down
Extend the selectionShift with any of the aboveShift with any of the above
Newline through the indenterEnter, numpad EnterEnter
Indent the caret or the selected linesTabTab
Outdent the selected linesShift+TabShift+Tab
Delete backward (an empty auto closed pair goes in one go)BackspaceBackspace
Delete forwardDeleteForward Delete (Fn+Delete on a Mac keyboard)
UndoCtrl+ZCmd+Z
RedoCtrl+Shift+Z, Ctrl+YShift+Cmd+Z
Select allCtrl+ACmd+A
Copy, cut, pasteCtrl+C, Ctrl+X, Ctrl+V, the dedicated keysCmd+C, Cmd+X, Cmd+V
Collapse the selection to the caretEscapeEscape

When readOnly is on, movement, selection, select all, copy and Escape still work, and the editing keys do nothing. Moving by word skips spaces, then jumps over a run of ASCII letters, digits and _. Any other character, such as é or an emoji, is a step of its own. A paste reports the origin input in onChange, and undo and redo report undo and redo.

Android leaves Alt and Meta combinations and Ctrl+Tab to the system. iOS leaves Control combinations, and Option with any key other than Left and Right, to the system. When the editor and iOS both handle a key, the editor's command runs.

Undo on iOS​

On iOS, Cmd+Z, shake to undo and the three-finger undo gestures undo the same steps as undo() and redo(). On Android, the keys in the table and the ref methods are the way to undo.

The same table from JavaScript​

moveCaret(direction, { select }) drives the movement rows, so a toolbar can match the keyboard:

DirectionAndroidiOS
left, rightLeft, RightLeft, Right
wordLeft, wordRightCtrl+Left, Ctrl+RightOption+Left, Option+Right
lineStart, lineEndHome, EndHome, End
documentStart, documentEndCtrl+Home, Ctrl+EndCmd+Home, Cmd+End
up, downUp, DownUp, Down
pageUp, pageDownPage Up, Page DownPage Up, Page Down

typeText('\n'), indent(), outdent(), deleteBackward() and deleteForward() cover Enter, Tab, Shift+Tab, Backspace and Delete. The keyboard guide has the toolbar recipe.

Testing without a keyboard​

On an Android emulator with hw.keyboard=yes the host keyboard types into the editor, and adb shell input keyevent sends keys from a script. On the iOS simulator the Mac keyboard types into the editor, and with Connect Hardware Keyboard on, the Cmd and Option shortcuts work too.