Fix keyboard keys

This commit is contained in:
LukeGus
2025-09-06 00:31:36 -05:00
parent 198a5c2796
commit 53a3192443

View File

@@ -20,27 +20,34 @@ export function TerminalKeyboard({onSendInput}: TerminalKeyboardProps) {
onSendInput(text); onSendInput(text);
} }
} catch (err) { } catch (err) {
console.error("Failed to read clipboard:", err); console.error("Paste failed:", err);
} }
} }
}, [onSendInput]); }, [onSendInput]);
const onKeyPress = useCallback((button: string) => { const onKeyPress = useCallback((button: string) => {
const layoutMap: { [key: string]: string } = { if (button === "{shift}") {
"{shift}": "shift", setLayoutName("shift");
"{unshift}": "default",
"{symbols}": "symbols",
"{fn}": "fn",
"{abc}": "default",
};
if (layoutMap[button]) {
setLayoutName(layoutMap[button]);
return; return;
} }
if (button === "{unshift}") {
if (button === "{paste}") { setLayoutName("default");
handlePaste(); return;
}
if (button === "{more}") {
setLayoutName("more");
return;
}
if (button === "{less}") {
setLayoutName("default");
return;
}
if (button === "{hide}") {
setLayoutName("hide");
return;
}
if (button === "{unhide}") {
setLayoutName("default");
return; return;
} }
@@ -48,12 +55,16 @@ export function TerminalKeyboard({onSendInput}: TerminalKeyboardProps) {
setIsCtrl(prev => !prev); setIsCtrl(prev => !prev);
return; return;
} }
if (button === "{alt}") { if (button === "{alt}") {
setIsAlt(prev => !prev); setIsAlt(prev => !prev);
return; return;
} }
if (button === "{paste}") {
handlePaste();
return;
}
let input = button; let input = button;
const specialKeyMap: { [key: string]: string } = { const specialKeyMap: { [key: string]: string } = {
@@ -73,7 +84,6 @@ export function TerminalKeyboard({onSendInput}: TerminalKeyboardProps) {
if (isCtrl) { if (isCtrl) {
if (input.length === 1) { if (input.length === 1) {
const charCode = input.toUpperCase().charCodeAt(0); const charCode = input.toUpperCase().charCodeAt(0);
// @, A-Z, [, \, ], ^, _
if (charCode >= 64 && charCode <= 95) { if (charCode >= 64 && charCode <= 95) {
input = String.fromCharCode(charCode - 64); input = String.fromCharCode(charCode - 64);
} }
@@ -84,9 +94,16 @@ export function TerminalKeyboard({onSendInput}: TerminalKeyboardProps) {
input = `\x1b${input}`; input = `\x1b${input}`;
} }
try {
if (navigator.vibrate) {
navigator.vibrate(20); navigator.vibrate(20);
}
} catch (e) {
console.error("Vibration failed:", e);
}
onSendInput(input); onSendInput(input);
}, [isCtrl, isAlt, onSendInput, handlePaste]); }, [onSendInput, handlePaste, isCtrl, isAlt]);
const buttonTheme = [ const buttonTheme = [
{ {
@@ -96,6 +113,10 @@ export function TerminalKeyboard({onSendInput}: TerminalKeyboardProps) {
{ {
class: "hg-space-medium", class: "hg-space-medium",
buttons: "{enter} {backspace}", buttons: "{enter} {backspace}",
},
{
class: "hg-space-small",
buttons: "{hide} {less} {more}",
} }
]; ];
@@ -106,48 +127,53 @@ export function TerminalKeyboard({onSendInput}: TerminalKeyboardProps) {
buttonTheme.push({class: "key-active", buttons: "{alt}"}); buttonTheme.push({class: "key-active", buttons: "{alt}"});
} }
const layout = { return (
<div className="">
<Keyboard
layout={{
default: [ default: [
"{esc} {tab} {ctrl} {alt} {arrowLeft} {arrowRight} {arrowUp} {arrowDown}",
"q w e r t y u i o p", "q w e r t y u i o p",
"a s d f g h j k l", "a s d f g h j k l",
"{shift} z x c v b n m {backspace}", "{shift} z x c v b n m {backspace}",
"{symbols} {ctrl} {alt} {space} {enter}", "{hide} {more} {space} {enter}",
], ],
shift: [ shift: [
"{esc} {tab} {ctrl} {alt} {arrowLeft} {arrowRight} {arrowUp} {arrowDown}",
"Q W E R T Y U I O P", "Q W E R T Y U I O P",
"A S D F G H J K L", "A S D F G H J K L",
"{unshift} Z X C V B N M {backspace}", "{unshift} Z X C V B N M {backspace}",
"{symbols} {ctrl} {alt} {space} {enter}", "{hide} {more} {space} {enter}",
], ],
symbols: [ more: [
"{esc} {tab} {ctrl} {alt} {end} {home} {pgUp} {pgDn}",
"1 2 3 4 5 6 7 8 9 0", "1 2 3 4 5 6 7 8 9 0",
"! @ # $ % ^ & * ( )", "! @ # $ % ^ & * ( ) _ +",
"- _ = + [ ] { } \\ |", "[ ] { } | \ \ ; : ' \" , . / < >",
"~ ` ' \" ; : , . / < > ?", "F1 F2 F3 F4 F5 F6 F7 F8 F9 F10 F11 F12",
"{abc} {fn} {space} {backspace}", "{arrowLeft} {arrowRight} {arrowUp} {arrowDown} {paste} {backspace}",
"{hide} {less} {space} {enter}",
], ],
fn: [ hide: [
"F1 F2 F3 F4 F5 F6", "{unhide}"
"F7 F8 F9 F10 F11 F12",
"{esc} {tab} {home} {end}",
"{pgUp} {pgDn} {arrowUp} {arrowDown}",
"{abc} {arrowLeft} {arrowRight} {paste} {backspace}",
] ]
}; }}
layoutName={layoutName}
const display = { onKeyPress={onKeyPress}
"{shift}": "⇧", display={{
"{unshift}": "", "{shift}": "up",
"{backspace}": "", "{unshift}": "dn",
"{symbols}": "?123", "{backspace}": "back",
"{abc}": "abc", "{more}": "more",
"{fn}": "Fn", "{less}": "less",
"{space}": "space", "{space}": "space",
"{enter}": "enter", "{enter}": "enter",
"{arrowLeft}": "←", "{arrowLeft}": "←",
"{arrowRight}": "→", "{arrowRight}": "→",
"{arrowUp}": "↑", "{arrowUp}": "↑",
"{arrowDown}": "↓", "{arrowDown}": "↓",
"{hide}": "hide",
"{unhide}": "unhide",
"{esc}": "esc", "{esc}": "esc",
"{tab}": "tab", "{tab}": "tab",
"{ctrl}": "ctrl", "{ctrl}": "ctrl",
@@ -157,15 +183,7 @@ export function TerminalKeyboard({onSendInput}: TerminalKeyboardProps) {
"{home}": "home", "{home}": "home",
"{pgUp}": "pgUp", "{pgUp}": "pgUp",
"{pgDn}": "pgDn", "{pgDn}": "pgDn",
}; }}
return (
<div className="">
<Keyboard
layout={layout}
layoutName={layoutName}
onKeyPress={onKeyPress}
display={display}
theme={"hg-theme-default dark-theme"} theme={"hg-theme-default dark-theme"}
useTouchEvents={true} useTouchEvents={true}
disableButtonHold={true} disableButtonHold={true}