Browse Source

feat: add Mac keyboard mapping support for Control, Command and Option keys

dipfocus 4 months ago
parent
commit
9daf7dede7
1 changed files with 14 additions and 0 deletions
  1. 14 0
      chrome-extension/src/background/browser/page.ts

+ 14 - 0
chrome-extension/src/background/browser/page.ts

@@ -462,6 +462,20 @@ export default class Page {
 
   private _convertKey(key: string): KeyInput {
     const lowerKey = key.trim().toLowerCase();
+    const isMac = navigator.userAgent.toLowerCase().includes('mac os x');
+
+    if (isMac) {
+      if (lowerKey === 'control' || lowerKey === 'ctrl') {
+        return 'Meta' as KeyInput; // Use Command key on Mac
+      }
+      if (lowerKey === 'command' || lowerKey === 'cmd') {
+        return 'Meta' as KeyInput; // Map Command/Cmd to Meta on Mac
+      }
+      if (lowerKey === 'option' || lowerKey === 'opt') {
+        return 'Alt' as KeyInput; // Map Option/Opt to Alt on Mac
+      }
+    }
+
     const keyMap: { [key: string]: string } = {
       // Letters
       a: 'KeyA',