瀏覽代碼

Merge pull request #86 from dipfocus/feat/mac-keyboard-mapping

feat: Add Mac keyboard mapping support
Ashu 4 月之前
父節點
當前提交
cf8e8d9e6f
共有 1 個文件被更改,包括 14 次插入0 次删除
  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',