very basic code editing!
This commit is contained in:
20
keyboard.ts
20
keyboard.ts
@@ -1,3 +1,5 @@
|
||||
import { font } from "./font.ts";
|
||||
|
||||
const keyboard = new Map<number, {first: boolean, repeat: boolean, held: boolean}>();
|
||||
|
||||
export const K = {
|
||||
@@ -125,4 +127,22 @@ export const getKeysPressed = () => {
|
||||
return value.first || value.repeat;
|
||||
}).map(([key]) => key);
|
||||
return result;
|
||||
}
|
||||
|
||||
export const getKeyboardString = () => {
|
||||
let str = "";
|
||||
for (const key of getKeysPressed()) {
|
||||
let char = String.fromCharCode(key).toLowerCase();
|
||||
if (shiftKeyDown()) {
|
||||
if (char in shiftMap) {
|
||||
char = shiftMap[char as keyof typeof shiftMap];
|
||||
} else {
|
||||
char = char.toUpperCase();
|
||||
}
|
||||
}
|
||||
if (char in font) {
|
||||
str += char;
|
||||
}
|
||||
}
|
||||
return str;
|
||||
}
|
||||
Reference in New Issue
Block a user