Browse Source

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

dipfocus 4 tháng trước cách đây
mục cha
commit
9daf7dede7

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

@@ -462,6 +462,20 @@ export default class Page {
 
 
   private _convertKey(key: string): KeyInput {
   private _convertKey(key: string): KeyInput {
     const lowerKey = key.trim().toLowerCase();
     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 } = {
     const keyMap: { [key: string]: string } = {
       // Letters
       // Letters
       a: 'KeyA',
       a: 'KeyA',