1
0
mirror of https://github.com/sehugg/8bitworkshop.git synced 2024-06-01 05:41:31 +00:00

Capture Ctrl keys in keydown, not keypress

This commit is contained in:
Micah Cowan 2022-01-28 00:01:51 -08:00
parent b3d42f944b
commit 45ee1b5c28
2 changed files with 13 additions and 1 deletions

View File

@ -53,7 +53,7 @@ export enum KeyFlags {
export function _setKeyboardEvents(canvas:HTMLElement, callback:KeyboardCallback) {
canvas.onkeydown = (e) => {
callback(e.which, 0, KeyFlags.KeyDown|_metakeyflags(e));
if (e.which == 8 || e.which == 9 || e.which == 27) { // eat backspace, tab, escape keys
if (e.ctrlKey || e.which == 8 || e.which == 9 || e.which == 27) { // eat backspace, tab, escape keys
e.preventDefault();
}
};

View File

@ -303,6 +303,18 @@ export class AppleII extends BasicScanlineMachine {
case 39: code=21; break; // right
case 38: code=11; break; // up
case 40: code=10; break; // down
default:
if (flags & KeyFlags.Ctrl) {
code = key;
if (code >= 0x61 && code <= 0x7a)
code -= 32;
if (key >= 65 && code < 65+26) {
code -= 64; // ctrl
}
else {
code = 0;
}
}
}
if (code)
this.kbdlatch = (code | 0x80) & 0xff;