|
|
|
@ -6,6 +6,8 @@ class VirtualKeyboard {
|
|
|
|
this.ctrlLocked = false;
|
|
|
|
this.ctrlLocked = false;
|
|
|
|
this.altActive = false;
|
|
|
|
this.altActive = false;
|
|
|
|
this.altLocked = false;
|
|
|
|
this.altLocked = false;
|
|
|
|
|
|
|
|
this.shiftActive = false;
|
|
|
|
|
|
|
|
this.shiftLocked = false;
|
|
|
|
this._repeatTimer = null;
|
|
|
|
this._repeatTimer = null;
|
|
|
|
this._repeatInterval = null;
|
|
|
|
this._repeatInterval = null;
|
|
|
|
|
|
|
|
|
|
|
|
@ -13,6 +15,7 @@ class VirtualKeyboard {
|
|
|
|
this.sendBtn = document.getElementById('send-btn');
|
|
|
|
this.sendBtn = document.getElementById('send-btn');
|
|
|
|
this.ctrlKey = document.getElementById('ctrl-key');
|
|
|
|
this.ctrlKey = document.getElementById('ctrl-key');
|
|
|
|
this.altKey = document.getElementById('alt-key');
|
|
|
|
this.altKey = document.getElementById('alt-key');
|
|
|
|
|
|
|
|
this.shiftKey = document.getElementById('shift-key');
|
|
|
|
|
|
|
|
|
|
|
|
this.init();
|
|
|
|
this.init();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
@ -42,6 +45,10 @@ class VirtualKeyboard {
|
|
|
|
this.altKey.addEventListener('click', () => this.toggleModifier('alt'));
|
|
|
|
this.altKey.addEventListener('click', () => this.toggleModifier('alt'));
|
|
|
|
this.altKey.addEventListener('dblclick', () => this.lockModifier('alt'));
|
|
|
|
this.altKey.addEventListener('dblclick', () => this.lockModifier('alt'));
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Shift modifier
|
|
|
|
|
|
|
|
this.shiftKey.addEventListener('click', () => this.toggleModifier('shift'));
|
|
|
|
|
|
|
|
this.shiftKey.addEventListener('dblclick', () => this.lockModifier('shift'));
|
|
|
|
|
|
|
|
|
|
|
|
// Special keys
|
|
|
|
// Special keys
|
|
|
|
document.querySelectorAll('.key[data-key]').forEach((btn) => {
|
|
|
|
document.querySelectorAll('.key[data-key]').forEach((btn) => {
|
|
|
|
if (btn.classList.contains('modifier')) return;
|
|
|
|
if (btn.classList.contains('modifier')) return;
|
|
|
|
@ -94,20 +101,24 @@ class VirtualKeyboard {
|
|
|
|
|
|
|
|
|
|
|
|
handleKeyPress(key) {
|
|
|
|
handleKeyPress(key) {
|
|
|
|
this._haptic();
|
|
|
|
this._haptic();
|
|
|
|
// Check for shortcut keys like Ctrl-c
|
|
|
|
// Check for pre-built shortcut keys like Ctrl-c
|
|
|
|
if (key.startsWith('Ctrl-')) {
|
|
|
|
if (key.startsWith('Ctrl-') || key.startsWith('Alt-') || key.startsWith('Shift-')) {
|
|
|
|
this.onSendKey(key);
|
|
|
|
this.onSendKey(key);
|
|
|
|
return;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// Apply active modifiers
|
|
|
|
// Apply active modifiers
|
|
|
|
let finalKey = key;
|
|
|
|
let finalKey = key;
|
|
|
|
|
|
|
|
if (this.shiftActive) {
|
|
|
|
|
|
|
|
finalKey = `Shift-${finalKey}`;
|
|
|
|
|
|
|
|
if (!this.shiftLocked) this.deactivateModifier('shift');
|
|
|
|
|
|
|
|
}
|
|
|
|
if (this.ctrlActive) {
|
|
|
|
if (this.ctrlActive) {
|
|
|
|
finalKey = `Ctrl-${key}`;
|
|
|
|
finalKey = `Ctrl-${finalKey}`;
|
|
|
|
if (!this.ctrlLocked) this.deactivateModifier('ctrl');
|
|
|
|
if (!this.ctrlLocked) this.deactivateModifier('ctrl');
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (this.altActive) {
|
|
|
|
if (this.altActive) {
|
|
|
|
finalKey = `Alt-${key}`;
|
|
|
|
finalKey = `Alt-${finalKey}`;
|
|
|
|
if (!this.altLocked) this.deactivateModifier('alt');
|
|
|
|
if (!this.altLocked) this.deactivateModifier('alt');
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@ -117,19 +128,17 @@ class VirtualKeyboard {
|
|
|
|
toggleModifier(mod) {
|
|
|
|
toggleModifier(mod) {
|
|
|
|
this._haptic();
|
|
|
|
this._haptic();
|
|
|
|
if (mod === 'ctrl') {
|
|
|
|
if (mod === 'ctrl') {
|
|
|
|
if (this.ctrlLocked) {
|
|
|
|
if (this.ctrlLocked) { this.deactivateModifier('ctrl'); return; }
|
|
|
|
this.deactivateModifier('ctrl');
|
|
|
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
this.ctrlActive = !this.ctrlActive;
|
|
|
|
this.ctrlActive = !this.ctrlActive;
|
|
|
|
this.ctrlKey.classList.toggle('active', this.ctrlActive);
|
|
|
|
this.ctrlKey.classList.toggle('active', this.ctrlActive);
|
|
|
|
} else if (mod === 'alt') {
|
|
|
|
} else if (mod === 'alt') {
|
|
|
|
if (this.altLocked) {
|
|
|
|
if (this.altLocked) { this.deactivateModifier('alt'); return; }
|
|
|
|
this.deactivateModifier('alt');
|
|
|
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
this.altActive = !this.altActive;
|
|
|
|
this.altActive = !this.altActive;
|
|
|
|
this.altKey.classList.toggle('active', this.altActive);
|
|
|
|
this.altKey.classList.toggle('active', this.altActive);
|
|
|
|
|
|
|
|
} else if (mod === 'shift') {
|
|
|
|
|
|
|
|
if (this.shiftLocked) { this.deactivateModifier('shift'); return; }
|
|
|
|
|
|
|
|
this.shiftActive = !this.shiftActive;
|
|
|
|
|
|
|
|
this.shiftKey.classList.toggle('active', this.shiftActive);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@ -142,6 +151,10 @@ class VirtualKeyboard {
|
|
|
|
this.altActive = true;
|
|
|
|
this.altActive = true;
|
|
|
|
this.altLocked = true;
|
|
|
|
this.altLocked = true;
|
|
|
|
this.altKey.classList.add('active', 'locked');
|
|
|
|
this.altKey.classList.add('active', 'locked');
|
|
|
|
|
|
|
|
} else if (mod === 'shift') {
|
|
|
|
|
|
|
|
this.shiftActive = true;
|
|
|
|
|
|
|
|
this.shiftLocked = true;
|
|
|
|
|
|
|
|
this.shiftKey.classList.add('active', 'locked');
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@ -154,6 +167,10 @@ class VirtualKeyboard {
|
|
|
|
this.altActive = false;
|
|
|
|
this.altActive = false;
|
|
|
|
this.altLocked = false;
|
|
|
|
this.altLocked = false;
|
|
|
|
this.altKey.classList.remove('active', 'locked');
|
|
|
|
this.altKey.classList.remove('active', 'locked');
|
|
|
|
|
|
|
|
} else if (mod === 'shift') {
|
|
|
|
|
|
|
|
this.shiftActive = false;
|
|
|
|
|
|
|
|
this.shiftLocked = false;
|
|
|
|
|
|
|
|
this.shiftKey.classList.remove('active', 'locked');
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|