From f7048d1e9f6ca3d26b949d878139b95be6c93593 Mon Sep 17 00:00:00 2001 From: ChaoticByte <9070224-ChaoticByte@users.noreply.gitlab.com> Date: Mon, 13 Feb 2023 21:08:20 +0100 Subject: [PATCH] Fixed shift- and shift-lock buttons and backspace issues in simple-keyboard_configure.js #14 --- app/static/js/simple-keyboard_configure.js | 24 +++++++++++++++++----- 1 file changed, 19 insertions(+), 5 deletions(-) diff --git a/app/static/js/simple-keyboard_configure.js b/app/static/js/simple-keyboard_configure.js index eac5aa0..7d9bd46 100644 --- a/app/static/js/simple-keyboard_configure.js +++ b/app/static/js/simple-keyboard_configure.js @@ -7,14 +7,14 @@ "{tab} q w e r t z u i o p \u00FC +", "{lock} a s d f g h j k l \u00F6 \u00E4 #", "{shift} < y x c v b n m , . - {shift}", - ".com @ {space}", + "@ {space}", ], shift: [ '\u00B0 ! " \u00A7 $ % & / ( ) = ? ` {bksp}', "{tab} Q W E R T Z U I O P \u00DC *", "{lock} A S D F G H J K L \u00D6 \u00C4 '", "{shift} > Y X C V B N M ; : _ {shift}", - ".com @ {space}", + "@ {space}", ], } const layout_en = { @@ -23,14 +23,14 @@ "{tab} q w e r t y u i o p [ ] \\", "{lock} a s d f g h j k l ; '", "{shift} z x c v b n m , . / {shift}", - ".com @ {space}", + "@ {space}", ], shift: [ "~ ! @ # $ % ^ & * ( ) _ + {bksp}", "{tab} Q W E R T Y U I O P { } |", '{lock} A S D F G H J K L : "', "{shift} Z X C V B N M < > ? {shift}", - ".com @ {space}", + "@ {space}", ], } const layout_numeric = { @@ -72,15 +72,29 @@ } // virtual keyboard const Keyboard = window.SimpleKeyboard.default; - const myKeyboard = new Keyboard({ + const keyboard = new Keyboard({ theme: theme, // choose german layout if language is de, // else choose english layout layout: layout, onChange: (input) => { keyboardInputElement.value = input; + }, + onKeyPress: (button) => { + if (button === "{shift}" || button === "{lock}") handleShift(); } }); + // additional handlers + keyboardInputElement.addEventListener("input", event => { + keyboard.setInput(event.target.value); + }); + function handleShift(input) { + let currentLayout = keyboard.options.layoutName; + let shiftToggle = currentLayout === "default" ? "shift" : "default"; + keyboard.setOptions({ + layoutName: shiftToggle + }); + } } }); })() \ No newline at end of file