Allow variable width in font

This commit is contained in:
dylan
2023-05-08 21:39:08 -07:00
parent 107a5370b1
commit ad5acdeb12
6 changed files with 967 additions and 806 deletions

View File

@@ -62,6 +62,13 @@ export const shiftMap = {
"/": "?",
}
export const altMap = {
"w": "⬆",
"a": "⬅",
"s": "⬇",
"d": "➡",
}
addEventListener("keydown", (evt) => {
// console.log("keydown", evt.key, evt.key.charCodeAt(0));
const key = evt.key.charCodeAt(0);
@@ -119,6 +126,10 @@ export const ctrlKeyDown = () => {
return keyDown(K.CTRL_LEFT) || keyDown(K.CTRL_RIGHT);
}
export const altKeyDown = () => {
return keyDown(K.ALT_LEFT) || keyDown(K.ALT_RIGHT);
}
export const keyReleased = (key: string | number) => {
if (typeof key === "string") {
key = key.toUpperCase().charCodeAt(0);
@@ -147,7 +158,14 @@ export const getKeyboardString = () => {
char = char.toUpperCase();
}
}
if (char in font) {
if (altKeyDown()) {
if (char in altMap) {
char = altMap[char as keyof typeof altMap];
} else {
char = char.toUpperCase();
}
}
if (char in font.chars) {
str += char;
}
}