2016-11-05 19:07:57 +00:00
|
|
|
//
|
2017-10-21 14:52:35 +00:00
|
|
|
// Keyboard.cpp
|
2016-11-05 19:07:57 +00:00
|
|
|
// Clock Signal
|
|
|
|
//
|
2017-10-21 14:52:35 +00:00
|
|
|
// Created by Thomas Harte on 10/10/2017.
|
2018-05-13 19:19:52 +00:00
|
|
|
// Copyright 2017 Thomas Harte. All rights reserved.
|
2016-11-05 19:07:57 +00:00
|
|
|
//
|
|
|
|
|
2017-10-21 14:52:35 +00:00
|
|
|
#include "Keyboard.hpp"
|
2016-11-05 19:07:57 +00:00
|
|
|
|
2017-08-03 15:42:31 +00:00
|
|
|
using namespace Electron;
|
2016-11-05 19:07:57 +00:00
|
|
|
|
2020-05-21 03:34:26 +00:00
|
|
|
uint16_t KeyboardMapper::mapped_key_for_key(Inputs::Keyboard::Key key) const {
|
2017-10-21 14:52:35 +00:00
|
|
|
#define BIND(source, dest) case Inputs::Keyboard::Key::source: return Electron::Key::dest
|
|
|
|
switch(key) {
|
2020-03-03 04:10:18 +00:00
|
|
|
default: break;
|
|
|
|
|
|
|
|
BIND(BackTick, KeyCopy);
|
2021-02-03 01:37:15 +00:00
|
|
|
BIND(Backslash, KeyCopy);
|
2017-10-21 14:52:35 +00:00
|
|
|
|
|
|
|
BIND(k0, Key0); BIND(k1, Key1); BIND(k2, Key2); BIND(k3, Key3); BIND(k4, Key4);
|
|
|
|
BIND(k5, Key5); BIND(k6, Key6); BIND(k7, Key7); BIND(k8, Key8); BIND(k9, Key9);
|
|
|
|
BIND(Q, KeyQ); BIND(W, KeyW); BIND(E, KeyE); BIND(R, KeyR); BIND(T, KeyT);
|
|
|
|
BIND(Y, KeyY); BIND(U, KeyU); BIND(I, KeyI); BIND(O, KeyO); BIND(P, KeyP);
|
|
|
|
BIND(A, KeyA); BIND(S, KeyS); BIND(D, KeyD); BIND(F, KeyF); BIND(G, KeyG);
|
|
|
|
BIND(H, KeyH); BIND(J, KeyJ); BIND(K, KeyK); BIND(L, KeyL);
|
|
|
|
BIND(Z, KeyZ); BIND(X, KeyX); BIND(C, KeyC); BIND(V, KeyV);
|
|
|
|
BIND(B, KeyB); BIND(N, KeyN); BIND(M, KeyM);
|
|
|
|
|
|
|
|
BIND(Comma, KeyComma);
|
|
|
|
BIND(FullStop, KeyFullStop);
|
|
|
|
BIND(ForwardSlash, KeySlash);
|
|
|
|
BIND(Semicolon, KeySemiColon);
|
|
|
|
BIND(Quote, KeyColon);
|
|
|
|
|
|
|
|
BIND(Escape, KeyEscape);
|
|
|
|
BIND(F12, KeyBreak);
|
|
|
|
|
|
|
|
BIND(Left, KeyLeft); BIND(Right, KeyRight); BIND(Up, KeyUp); BIND(Down, KeyDown);
|
|
|
|
|
|
|
|
BIND(Tab, KeyFunc); BIND(LeftOption, KeyFunc); BIND(RightOption, KeyFunc);
|
|
|
|
BIND(LeftMeta, KeyFunc); BIND(RightMeta, KeyFunc);
|
|
|
|
BIND(CapsLock, KeyControl); BIND(LeftControl, KeyControl); BIND(RightControl, KeyControl);
|
|
|
|
BIND(LeftShift, KeyShift); BIND(RightShift, KeyShift);
|
|
|
|
|
|
|
|
BIND(Hyphen, KeyMinus);
|
2019-08-02 20:15:34 +00:00
|
|
|
BIND(Delete, KeyDelete); BIND(Backspace, KeyDelete);
|
2019-11-09 23:02:14 +00:00
|
|
|
BIND(Enter, KeyReturn); BIND(KeypadEnter, KeyReturn);
|
2017-10-21 14:52:35 +00:00
|
|
|
|
2019-11-09 23:02:14 +00:00
|
|
|
BIND(Keypad0, Key0); BIND(Keypad1, Key1); BIND(Keypad2, Key2); BIND(Keypad3, Key3); BIND(Keypad4, Key4);
|
|
|
|
BIND(Keypad5, Key5); BIND(Keypad6, Key6); BIND(Keypad7, Key7); BIND(Keypad8, Key8); BIND(Keypad9, Key9);
|
2017-10-21 14:52:35 +00:00
|
|
|
|
2019-11-09 23:02:14 +00:00
|
|
|
BIND(KeypadMinus, KeyMinus); BIND(KeypadPlus, KeyColon);
|
2017-10-21 14:52:35 +00:00
|
|
|
|
|
|
|
BIND(Space, KeySpace);
|
2020-03-06 02:01:30 +00:00
|
|
|
|
|
|
|
// Virtual mappings.
|
|
|
|
BIND(F1, KeyF1);
|
|
|
|
BIND(F2, KeyF2);
|
|
|
|
BIND(F3, KeyF3);
|
|
|
|
BIND(F4, KeyF4);
|
|
|
|
BIND(F5, KeyF5);
|
|
|
|
BIND(F6, KeyF6);
|
|
|
|
BIND(F7, KeyF7);
|
|
|
|
BIND(F8, KeyF8);
|
|
|
|
BIND(F9, KeyF9);
|
|
|
|
BIND(F10, KeyF0);
|
2017-10-21 14:52:35 +00:00
|
|
|
}
|
|
|
|
#undef BIND
|
2020-04-02 03:19:34 +00:00
|
|
|
return MachineTypes::MappedKeyboardMachine::KeyNotMapped;
|
2017-10-21 14:52:35 +00:00
|
|
|
}
|
|
|
|
|
2020-05-21 03:34:26 +00:00
|
|
|
const uint16_t *CharacterMapper::sequence_for_character(char character) const {
|
2020-04-02 03:19:34 +00:00
|
|
|
#define KEYS(...) {__VA_ARGS__, MachineTypes::MappedKeyboardMachine::KeyEndSequence}
|
|
|
|
#define SHIFT(...) {KeyShift, __VA_ARGS__, MachineTypes::MappedKeyboardMachine::KeyEndSequence}
|
|
|
|
#define CTRL(...) {KeyControl, __VA_ARGS__, MachineTypes::MappedKeyboardMachine::KeyEndSequence}
|
|
|
|
#define X {MachineTypes::MappedKeyboardMachine::KeyNotMapped}
|
2017-07-22 01:18:51 +00:00
|
|
|
static KeySequence key_sequences[] = {
|
2016-11-05 19:07:57 +00:00
|
|
|
/* NUL */ X, /* SOH */ X,
|
|
|
|
/* STX */ X, /* ETX */ X,
|
|
|
|
/* EOT */ X, /* ENQ */ X,
|
|
|
|
/* ACK */ X, /* BEL */ X,
|
|
|
|
/* BS */ KEYS(KeyDelete), /* HT */ X,
|
|
|
|
/* LF */ KEYS(KeyReturn), /* VT */ X,
|
2020-03-01 00:26:15 +00:00
|
|
|
/* FF */ X, /* CR */ KEYS(KeyReturn),
|
2016-11-05 19:07:57 +00:00
|
|
|
/* SO */ X, /* SI */ X,
|
|
|
|
/* DLE */ X, /* DC1 */ X,
|
|
|
|
/* DC2 */ X, /* DC3 */ X,
|
|
|
|
/* DC4 */ X, /* NAK */ X,
|
|
|
|
/* SYN */ X, /* ETB */ X,
|
|
|
|
/* CAN */ X, /* EM */ X,
|
|
|
|
/* SUB */ X, /* ESC */ X,
|
|
|
|
/* FS */ X, /* GS */ X,
|
|
|
|
/* RS */ X, /* US */ X,
|
|
|
|
/* space */ KEYS(KeySpace), /* ! */ SHIFT(Key1),
|
|
|
|
/* " */ SHIFT(Key2), /* # */ SHIFT(Key3),
|
|
|
|
/* $ */ SHIFT(Key4), /* % */ SHIFT(Key5),
|
|
|
|
/* & */ SHIFT(Key6), /* ' */ SHIFT(Key7),
|
|
|
|
/* ( */ SHIFT(Key8), /* ) */ SHIFT(Key9),
|
|
|
|
/* * */ SHIFT(KeyColon), /* + */ SHIFT(KeySemiColon),
|
|
|
|
/* , */ KEYS(KeyComma), /* - */ KEYS(KeyMinus),
|
|
|
|
/* . */ KEYS(KeyFullStop), /* / */ KEYS(KeySlash),
|
|
|
|
/* 0 */ KEYS(Key0), /* 1 */ KEYS(Key1),
|
|
|
|
/* 2 */ KEYS(Key2), /* 3 */ KEYS(Key3),
|
|
|
|
/* 4 */ KEYS(Key4), /* 5 */ KEYS(Key5),
|
|
|
|
/* 6 */ KEYS(Key6), /* 7 */ KEYS(Key7),
|
|
|
|
/* 8 */ KEYS(Key8), /* 9 */ KEYS(Key9),
|
|
|
|
/* : */ KEYS(KeyColon), /* ; */ KEYS(KeySemiColon),
|
|
|
|
/* < */ SHIFT(KeyComma), /* = */ SHIFT(KeyMinus),
|
|
|
|
/* > */ SHIFT(KeyFullStop), /* ? */ SHIFT(KeySlash),
|
|
|
|
/* @ */ SHIFT(Key0), /* A */ KEYS(KeyA),
|
|
|
|
/* B */ KEYS(KeyB), /* C */ KEYS(KeyC),
|
|
|
|
/* D */ KEYS(KeyD), /* E */ KEYS(KeyE),
|
|
|
|
/* F */ KEYS(KeyF), /* G */ KEYS(KeyG),
|
|
|
|
/* H */ KEYS(KeyH), /* I */ KEYS(KeyI),
|
|
|
|
/* J */ KEYS(KeyJ), /* K */ KEYS(KeyK),
|
|
|
|
/* L */ KEYS(KeyL), /* M */ KEYS(KeyM),
|
|
|
|
/* N */ KEYS(KeyN), /* O */ KEYS(KeyO),
|
|
|
|
/* P */ KEYS(KeyP), /* Q */ KEYS(KeyQ),
|
|
|
|
/* R */ KEYS(KeyR), /* S */ KEYS(KeyS),
|
|
|
|
/* T */ KEYS(KeyT), /* U */ KEYS(KeyU),
|
|
|
|
/* V */ KEYS(KeyV), /* W */ KEYS(KeyW),
|
|
|
|
/* X */ KEYS(KeyX), /* Y */ KEYS(KeyY),
|
|
|
|
/* Z */ KEYS(KeyZ), /* [ */ SHIFT(KeyCopy),
|
|
|
|
/* \ */ CTRL(KeyRight), /* ] */ CTRL(KeyCopy),
|
|
|
|
/* ^ */ SHIFT(KeyLeft), /* _ */ SHIFT(KeyDown),
|
|
|
|
/* ` */ X, /* a */ SHIFT(KeyA),
|
|
|
|
/* b */ SHIFT(KeyB), /* c */ SHIFT(KeyC),
|
|
|
|
/* d */ SHIFT(KeyD), /* e */ SHIFT(KeyE),
|
|
|
|
/* f */ SHIFT(KeyF), /* g */ SHIFT(KeyG),
|
|
|
|
/* h */ SHIFT(KeyH), /* i */ SHIFT(KeyI),
|
|
|
|
/* j */ SHIFT(KeyJ), /* k */ SHIFT(KeyK),
|
|
|
|
/* l */ SHIFT(KeyL), /* m */ SHIFT(KeyM),
|
|
|
|
/* n */ SHIFT(KeyN), /* o */ SHIFT(KeyO),
|
|
|
|
/* p */ SHIFT(KeyP), /* q */ SHIFT(KeyQ),
|
|
|
|
/* r */ SHIFT(KeyR), /* s */ SHIFT(KeyS),
|
|
|
|
/* t */ SHIFT(KeyT), /* u */ SHIFT(KeyU),
|
|
|
|
/* v */ SHIFT(KeyV), /* w */ SHIFT(KeyW),
|
|
|
|
/* x */ SHIFT(KeyX), /* y */ SHIFT(KeyY),
|
|
|
|
/* z */ SHIFT(KeyZ), /* { */ CTRL(KeyUp),
|
|
|
|
/* | */ SHIFT(KeyRight), /* } */ CTRL(KeyDown),
|
2020-03-03 04:10:18 +00:00
|
|
|
/* ~ */ CTRL(KeyLeft)
|
2016-11-05 19:07:57 +00:00
|
|
|
};
|
|
|
|
#undef KEYS
|
|
|
|
#undef SHIFT
|
|
|
|
#undef X
|
|
|
|
|
2017-07-22 01:18:51 +00:00
|
|
|
return table_lookup_sequence_for_character(key_sequences, sizeof(key_sequences), character);
|
2016-11-05 19:07:57 +00:00
|
|
|
}
|
2020-03-01 00:26:15 +00:00
|
|
|
|
2020-05-21 03:34:26 +00:00
|
|
|
bool CharacterMapper::needs_pause_after_key(uint16_t key) const {
|
2020-03-01 00:26:15 +00:00
|
|
|
return key != KeyControl && key != KeyShift && key != KeyFunc;
|
|
|
|
}
|