This commit is contained in:
Julian Barathieu 2020-01-16 17:44:03 +01:00
parent 2f1fefe724
commit 057052244c
2 changed files with 29 additions and 24 deletions

View File

@ -28,37 +28,44 @@
#include "scan.c"
#define KEY(code) (table[2*(code)])
#define FLAGS(code) (table[2*(code)+1])
static bool capsLockActive = 0;
static bool leftAltPressed = 0;
static bool leftShiftPressed = 0;
static bool leftControlPressed = 0;
static bool altPressed = 0;
static bool shiftPressed = 0;
static bool controlPressed = 0;
void KeybPrint(uchar _code)
{
uint code = (uint)_code;
const uint *table =
(leftAltPressed ? LeftAltScanCodes
: (leftShiftPressed ? LeftShiftScanCodes
: (leftControlPressed ? LeftControlScanCodes
(altPressed ? LeftAltScanCodes
: (controlPressed ? LeftControlScanCodes
: (shiftPressed ? LeftShiftScanCodes
: RegularScanCodes)));
if (capsLockActive && !leftShiftPressed &&
!!(table[2 * code + 1] & CAPSLOCK) && !leftAltPressed)
if (capsLockActive && (FLAGS(code) & CAPSLOCK))
&& !(altPressed || controlPressed)) {
if (shiftPressed)
table = RegularScanCodes;
else
table = LeftShiftScanCodes;
}
uchar ch = table[2 * code];
uchar ch = KEY(code);
if (!ch) {
switch (code) {
case 0x38: leftAltPressed = 1; break;
case 0xB8: leftAltPressed = 0; break;
case 0x38: altPressed = 1; break;
case 0xB8: altPressed = 0; break;
case 0x36: case 0x2A: leftShiftPressed = 1; break;
case 0xB6: case 0xAA: leftShiftPressed = 0; break;
case 0x36: case 0x2A: shiftPressed = 1; break;
case 0xB6: case 0xAA: shiftPressed = 0; break;
case 0x1D: leftControlPressed = 1; break;
case 0x9D: leftControlPressed = 0; break;
case 0x1D: controlPressed = 1; break;
case 0x9D: controlPressed = 0; break;
case 0x3A: capsLockActive = !capsLockActive; break;
}
@ -66,7 +73,7 @@ void KeybPrint(uchar _code)
}
bputc(BStdIn, ch);
if (code && (table[2 * code + 1] & INVISIBLE) == 0) {
if (code && (FLAGS(code) & INVISIBLE) == 0) {
bputc(BStdOut, table[2 * code]);
BStdOut->flusher(BStdOut);
}

View File

@ -94,7 +94,10 @@ const uint RegularScanCodes[2 * 256] =
ENTRY (0x33, ';', CAPSLOCK),
ENTRY (0x34, ':', CAPSLOCK),
ENTRY (0x35, '!', CAPSLOCK),
ENTRY (0x39, ' ', NONE),
};
const uint LeftShiftScanCodes[2 * 256] =
{
ENTRY (0x00, 0, INVISIBLE|INVALID),
@ -157,15 +160,10 @@ const uint LeftShiftScanCodes[2 * 256] =
ENTRY (0x33, '.', NONE),
ENTRY (0x34, '/', NONE),
ENTRY (0x35, '!', NONE),
ENTRY (0x39, ' ', NONE),
};
const uint LeftAltScanCodes[2 * 256];
const uint LeftControlScanCodes[2 * 256];