Skip to content

Potential fix for CMD key woes in macOS #159

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions web/share/js/kvm/keyboard.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ export function Keyboard(__recordWsEvent) {
var __online = true;

var __keypad = null;
var __metaKeyDown = false;

var __init__ = function() {
__keypad = new Keypad("div#keyboard-window", __sendKey, true);
Expand Down Expand Up @@ -126,9 +127,26 @@ export function Keyboard(__recordWsEvent) {

var __keyboardHandler = function(event, state) {
event.preventDefault();
__keyboardMetaKeyFixer(event, state);
__keypad.emitByKeyEvent(event, state);
};

var __keyboardMetaKeyFixer = function(event, state) {
var ignoreList = ["AltLeft", "AltRight", "ControlLeft", "ControlRight",
"ShiftLeft", "ShiftRight"];

if (event.code === "MetaLeft" || event.code === "MetaRight") {
tools.debug("Keyboard: MetaKeyMode set:", state);
__metaKeyDown = state;
} else if (__metaKeyDown) {
if (state && !ignoreList.includes(event.code)) {
tools.debug("Keyboard: Forced keyUp:", event);
setTimeout(() => __keypad.emitByKeyEvent(event, false));
}
}
return true;
}

var __sendKey = function(code, state) {
tools.debug("Keyboard: key", (state ? "pressed:" : "released:"), code);
if ($("hid-keyboard-swap-cc-switch").checked) {
Expand Down