avoid using key code '0'

This commit is contained in:
Jorj Bauer 2021-01-19 22:28:14 -05:00
parent d42a88e083
commit 6f47723b8a
2 changed files with 9 additions and 6 deletions

View File

@ -22,6 +22,9 @@
#define PK_LA 0x85 // left (open) apple, aka paddle0 button #define PK_LA 0x85 // left (open) apple, aka paddle0 button
#define PK_RA 0x86 // right (closed) apple aka paddle1 button #define PK_RA 0x86 // right (closed) apple aka paddle1 button
#define PK_NONE 0xFF // not a key; but 0x00 is used internally by the
// library, and I don't want to harsh its buzz
class PhysicalKeyboard { class PhysicalKeyboard {
public: public:
PhysicalKeyboard(VMKeyboard *k) { this->vmkeyboard = k; } PhysicalKeyboard(VMKeyboard *k) { this->vmkeyboard = k; }

View File

@ -13,8 +13,8 @@ char keys[ROWS][COLS] = {
{ '1', '2', '3', '4', '5', '6', '7', '8', '9', '0', '-', '=', PK_DEL }, { '1', '2', '3', '4', '5', '6', '7', '8', '9', '0', '-', '=', PK_DEL },
{ PK_ESC, 'q', 'w', 'e', 'r', 't', 'y', 'u', 'i', 'o', 'p', '[', ']' }, { PK_ESC, 'q', 'w', 'e', 'r', 't', 'y', 'u', 'i', 'o', 'p', '[', ']' },
{ PK_CTRL, 'a', 's', 'd', 'f', 'g', 'h', 'j', 'k', 'l', ';', '\'', PK_RET }, { PK_CTRL, 'a', 's', 'd', 'f', 'g', 'h', 'j', 'k', 'l', ';', '\'', PK_RET },
{ PK_LSHFT, 'z', 'x', 'c', 'v', 'b', 'n', 'm', ',', '.', '/', PK_RSHFT, 0 }, { PK_LSHFT, 'z', 'x', 'c', 'v', 'b', 'n', 'm', ',', '.', '/', PK_RSHFT, PK_NONE },
{ PK_LOCK, '`', PK_TAB, '\\', PK_LA, ' ', PK_RA, PK_LARR, PK_RARR, PK_DARR, PK_UARR, 0, 0 } { PK_LOCK, '`', PK_TAB, '\\', PK_LA, ' ', PK_RA, PK_LARR, PK_RARR, PK_DARR, PK_UARR, PK_NONE, PK_NONE }
}; };
uint8_t rowsPins[ROWS] = { 33, 34, 35, 36, 37 }; uint8_t rowsPins[ROWS] = { 33, 34, 35, 36, 37 };
@ -81,8 +81,8 @@ static uint8_t shiftedNumber[] = { '<', // ,
TeensyKeyboard::TeensyKeyboard(VMKeyboard *k) : PhysicalKeyboard(k) TeensyKeyboard::TeensyKeyboard(VMKeyboard *k) : PhysicalKeyboard(k)
{ {
keypad.setDebounceTime(5); keypad.setDebounceTime(10);
leftShiftPressed = false; leftShiftPressed = false;
rightShiftPressed = false; rightShiftPressed = false;
ctrlPressed = false; ctrlPressed = false;
@ -100,7 +100,6 @@ TeensyKeyboard::~TeensyKeyboard()
void TeensyKeyboard::pressedKey(uint8_t key) void TeensyKeyboard::pressedKey(uint8_t key)
{ {
numPressed++; numPressed++;
if (key & 0x80) { if (key & 0x80) {
// it's a modifier key. // it's a modifier key.
switch (key) { switch (key) {
@ -124,6 +123,7 @@ void TeensyKeyboard::pressedKey(uint8_t key)
rightApplePressed = 1; rightApplePressed = 1;
break; break;
} }
addEvent(key, true);
return; return;
} }
@ -219,7 +219,7 @@ bool TeensyKeyboard::kbhit()
{ {
if (keypad.getKeys()) { if (keypad.getKeys()) {
for (int i=0; i<LIST_MAX; i++) { for (int i=0; i<LIST_MAX; i++) {
if ( keypad.key[i].stateChanged ) { if ( keypad.key[i].stateChanged && keypad.key[i].kchar != PK_NONE ) {
switch (keypad.key[i].kstate) { switch (keypad.key[i].kstate) {
case PRESSED: case PRESSED:
pressedKey(keypad.key[i].kchar); pressedKey(keypad.key[i].kchar);