2011年12月11日 星期日

[設定] 在 Mac 上自訂 Windows 按鍵習慣 - Part I 基本設定

1. 前言

當 Windows user 第一次使用 Mac,往往會對鍵盤感到不習慣。

Mac 筆電鍵盤相較 PC 鍵盤,缺了幾個鍵:
  • Insert, PgUp, PgDown, Home, End 
  • Win 鍵 
但其他按鍵功能也有一些不同之處
  • Command, Option, Control 三個控制鍵,並非單純對應到 PC 鍵盤的 Control & Alt,而是有一個蠻複雜的對應關係。
  • Delete 鍵較類似 PC 的 Backspace 鍵,要用到類似 PC Delete 鍵的功能得改按 Command+Del 或 Fn+Del。
其實 Mac 的鍵盤設計對 Unix 使用者是比較好用的,它可同時用上 Emacs 的 Control, Meta 以及 Mac 的 Command 三組控制鍵,不會互相打架,而 GNU 工具 (如 bash 或 gdb) 往往內建 Emacs 按鍵設計。所以如果沒有 PC 的包袱,最好是從一開始就習慣 Mac 鍵盤,下面就不用繼續看下去了。
-------------------------------
可惜現實往往不會這麼理想,經常還是要用到 Windows,下面就介紹怎樣讓 Mac 的鍵盤改到幾乎符合 PC 的操作習慣,以減少在 Mac & Windows 間切換的困擾。

設定步驟看起來很繁雜,但原理不難。只要了解原理後,就能夠按照每個人不同的需求去自訂了。


2. Control, Option, Command 的對應關係

Mac 鍵盤對應到 PC 鍵盤的相對位置如下:


下面會示範如何把 Mac 鍵盤改成藍色字對應的 PC 按鍵,後面會一一解釋理由。

首先得先了解 Mac 鍵盤的設計受到 Emacs 影響,Emacs 發源於約三十五年前,比 Apple II 還早了好幾年,第一台 PC 也尚未問世。早年鍵盤跟今日很不同,因此 Emacs 採用特殊的控制鍵,早年 Emacs 「定義」了兩個主要的控制鍵,叫做 Control 及 Meta 鍵。

Mac 控制鍵跟 PC, Emacs 的關係為:
  • Control 鍵
    • PC  對應: 雖然也叫 Control, 但和 Windows 的 Control 鍵功能完全不同
    • Emacs 對應: 等於 Emacs 的 Control 鍵
    • 按鍵位置: 在 PC 鍵盤的 Control 位置上
    • BootCamp: 在 Windows 內當成 Control 鍵使用
  • Alt/Option 鍵
    • PC    對應: 跟 Windows 上任一按鍵均不同
    • Emacs 對應: 等於 Emacs 的 Meta 鍵
    • 按鍵位置: 在 PC 鍵盤的 Win 位置上
    • BootCamp: 在 Windows 內當成 Alt 鍵使用
  • Command 鍵
    • PC   對應:功能上非常類似 PC 的 Control 鍵,是 Mac 主要的控制鍵
    • Emacs 對應: 與 Emacs 無關
    • 按鍵位置: 在 PC 鍵盤的 Alt 位置上
    • BootCamp: 在 Windows 內當成 Win 鍵使用
很複雜吧?! 我花了一段時間才搞懂。


3. 將 Control & Command 鍵對調

接下來最簡單的事情是對調 Control & Command 這兩個鍵,在 PC 上 Control 鍵對應的熱鍵,在 Mac 上幾乎全部都跟 Command 鍵都一一對應 (Alt-Tab 是唯一例外),但 Command 及 Control 鍵在鍵盤上位置不同,這也是在 PC/Mac 間切換時,常常會按錯鍵的原因,比如:
  • Command+空白鍵 切換中文輸入法
  • Command+C 複製
  • Command+V 貼上
  • Command+X 剪下
  • Command+N Open New File/Window
  • Command+T Open New Tab (in browser)
  • Command+L Goto Link (in browser)
  • Command+W Close Window/Tab
  • Command+S Save File
  • Command+滑鼠左鍵  一一選擇檔案、照片,或者在網頁上開啟新分頁
此外 Mac 上應用程式還自己定義了很多 Command 鍵的組合熱鍵,所以要符合 PC 習慣最簡單的方法就是直接對調 Command & Control 兩個按鍵。

打開「系統偏好設定」-> 「鍵盤」 -> 「變更鍵」,把 Command 指定到 Control 鍵,把 Control 指定到 Command 鍵:


請注意:如果筆電有外接鍵盤,內建鍵盤及外接鍵盤都要分別設定一次。

4. 使用 KeyRemap4MacBook 對應例外按鍵

KeyRemap4MacKook 是一套很神奇的免費軟體,可以用 XML 非常有彈性的定義按鍵設定。你可以安裝 KeyRemap4MacBook 後,進入「系統偏好設定」 可看到 KeyRemap4MacBook 圖示,進入會出現以下畫面


接著把下面的 XML 貼到 ~/Library/Application Support/KeyRemap4MacBook/private.xml 下儲存,再點選上面視窗的 "Reload XML"。

前面就會出現一些自己新增的選項,打開這些選項,就能讓 Mac 的按鍵習慣更加貼近 PC:


以下為 private.xml 的內容:

<?xml version="1.0"?>
<root>
  <!-- By default in OS X Lion, F4 is mapped to Dashboard (internal keyboard) or 
       Lauchpad (on wireless keyboard) -->
  <item>
    <name>Control+F4 to Command+Q</name>
    <identifier>private.control_f4_to_command_q</identifier>
    <not>REMOTEDESKTOPCONNECTION,VIRTUALMACHINE</not>
    <autogen>--KeyToKey-- KeyCode::F4, VK_CONTROL, KeyCode::Q, ModifierFlag::COMMAND_L </autogen>
    <autogen>--KeyToKey-- KeyCode::DASHBOARD, VK_CONTROL, KeyCode::Q, ModifierFlag::COMMAND_L </autogen>    
    <autogen>--KeyToKey-- KeyCode::LAUNCHPAD, VK_CONTROL, KeyCode::Q, ModifierFlag::COMMAND_L </autogen>    
  </item>


  <!--  Ctrl-Left/Right -->  
  <item>
    <name>Command-Left/Right to Option-Left/Right</name>
    <identifier>private.command_left_right_to_option_left_right</identifier>
    <not>REMOTEDESKTOPCONNECTION,VIRTUALMACHINE,EMACS</not>
    <autogen>--KeyToKey--
    KeyCode::CURSOR_LEFT,  VK_COMMAND,
    KeyCode::CURSOR_LEFT,  ModifierFlag::OPTION_L
    </autogen>
    <autogen>--KeyToKey--
    KeyCode::CURSOR_RIGHT, VK_COMMAND,
    KeyCode::CURSOR_RIGHT, ModifierFlag::OPTION_L
    </autogen>
  </item>



  <!--  Swap Command-Tab and Control-Tab -->  
  <item>
    <name>Swap Command+Tab and Control+Tab</name>
    <identifier>private.remap.swap_commandtabcontroltab</identifier>
    <not>REMOTEDESKTOPCONNECTION,VIRTUALMACHINE</not>
    <autogen>--KeyToKey-- KeyCode::TAB, VK_CONTROL, KeyCode::TAB, ModifierFlag::COMMAND_L</autogen>
    <autogen>--KeyToKey-- KeyCode::TAB, VK_COMMAND, KeyCode::TAB, ModifierFlag::CONTROL_L</autogen>
  </item>



  <!-- The following settings are for MS-Windows in virtual machine -->
  <item>
    <name>Restore the original modifiers layout in RDC and VM</name>
    <appendix>(if Ctrl/Command modifiers are swapped in System Preference)</appendix>
    <only>REMOTEDESKTOPCONNECTION,VIRTUALMACHINE</only>
    <identifier>private.app_vm_rdc_reset_modifiers_layout</identifier>
    <autogen>--KeyToKey-- KeyCode::COMMAND_L, KeyCode::CONTROL_L</autogen>
    <autogen>--KeyToKey-- KeyCode::COMMAND_R, KeyCode::CONTROL_R</autogen>    
    <autogen>--KeyToKey-- KeyCode::CONTROL_L, KeyCode::COMMAND_L</autogen>
    <autogen>--KeyToKey-- KeyCode::CONTROL_R, KeyCode::COMMAND_R</autogen>
  </item>


  <item>
    <name>Use F1~F12 as function key in RDC and VM</name>
    <only>REMOTEDESKTOPCONNECTION,VIRTUALMACHINE</only>
    <identifier>private.app_vm_rdc_use_function_key</identifier>
    <autogen>--KeyToKey-- KeyCode::BRIGHTNESS_DOWN, KeyCode::F1 </autogen>    
    <autogen>--ConsumerToKey-- ConsumerKeyCode::BRIGHTNESS_DOWN, KeyCode::F1 </autogen>
    <autogen>--KeyToKey-- KeyCode::BRIGHTNESS_UP, KeyCode::F2 </autogen>
    <autogen>--ConsumerToKey-- ConsumerKeyCode::BRIGHTNESS_UP, KeyCode::F2 </autogen>
    <autogen>--KeyToKey-- KeyCode::EXPOSE_ALL, KeyCode::F3 </autogen>
    <autogen>--KeyToKey-- KeyCode::DASHBOARD, KeyCode::F4 </autogen>
    <autogen>--KeyToKey-- KeyCode::LAUNCHPAD, KeyCode::F4 </autogen>
    <autogen>--ConsumerToKey-- ConsumerKeyCode::KEYBOARDLIGHT_LOW, KeyCode::F5 </autogen>
    <autogen>--ConsumerToKey-- ConsumerKeyCode::KEYBOARDLIGHT_HIGH, KeyCode::F6 </autogen>
    <autogen>--ConsumerToKey-- ConsumerKeyCode::MUSIC_PREV, KeyCode::F7 </autogen>
    <autogen>--ConsumerToKey-- ConsumerKeyCode::MUSIC_PLAY, KeyCode::F8 </autogen>
    <autogen>--ConsumerToKey-- ConsumerKeyCode::MUSIC_NEXT, KeyCode::F9 </autogen>
    <autogen>--ConsumerToKey-- ConsumerKeyCode::VOLUME_MUTE, KeyCode::F10 </autogen>
    <autogen>--ConsumerToKey-- ConsumerKeyCode::VOLUME_DOWN, KeyCode::F11 </autogen>
    <autogen>--ConsumerToKey-- ConsumerKeyCode::VOLUME_UP, KeyCode::F12 </autogen>
  </item>  
</root>

4.1 XML 說明

這邊簡單介紹每一項的功能,首先先看在 VMWare, Parallels, Demote Desktop 等 Windows 畫面中關閉,但適用於一般 Mac 應用程式的設定:

  • Control+F4 to Command+Q
    • 因為 Mac 關閉應用程式是按 Command+Q,但 Windows 是按 Alt+F4,這邊讓Alt+F4 可關閉程式。
  • Command-Left/Right to Option-Left/Right
    • Mac 受到 Emacs 影響,使用 Option+左右鍵去前後跳一個英文字,但在 Windows 是按 Ctrl+左右鍵,這邊讓 Ctrl+左右鍵也可以前後跳一個英文字。
  • Swap Command+Tab and Control+Tab
    • 因為 Mac 是按 Command+Tab 切換應用程式,前面已經把 Command 跟 Control key 對調,這邊再對調回來,比較符合 Windows 按 Alt-Tab 切換應用程式的習慣。
另外兩項是在 VMWare, Parallels, Demote Desktop 等 Windows 畫面中才打開的功能:
  • Restore the original modifiers layout in RDC and VM
    • 前面已經把 Command 跟 Control key 對調,進 Windows 再對調回來。
  • Use F1~F12 as function key in RDC and VM
    • 平常 Mac 的 F1~F12 是作為特殊功能鍵如調整背光、播放音樂使用,但由於 Windows 太常使用這幾個功能鍵,所以這幾個鍵在 Windows 預設當做功能鍵。
這些 XML 大多是 KeyRemap4MacBook 的原作者所無償提供的,如果覺得好用的話,歡迎在他的網頁上小額捐款給原作者 (是一位日本人)。

5. VMWare 設定

完成前面幾項設定之後,Mac 的按鍵已經很接近 Windows 的習慣了。接下來 VMWare 還需要作一個小調整,因為 VMWare 自己也會做一些 Mac <-> Windows 間的按鍵對應,但又作半套,為了避免不必要的麻煩,建議把 VMWare 的 Key Mapping 關閉:


另外 VMWare 會把 Ctrl+滑鼠左鍵對應到其他鍵,這個功能最好也關掉,因為 Ctrl+滑鼠左鍵在 Windows 內還蠻常用的。



6. Windows 內設定

回憶最一開始提到 Alt/Option 鍵佔據 PC 鍵盤的 Win 鍵位置,而 Command 鍵佔據 PC 鍵盤的 Alt 鍵位置,在 Windows 內兩個鍵的位置剛好相反。

如果已經習慣 PC 鍵盤的配置,可以在 Windows 上安裝一套免費的軟體 SharpKeys,輸入以下對應後,在點「Save to Registory」,重新開機就完成了。


這個在 Windows 內把 Win 鍵以及 Alt 鍵對調的設定,不論是用 BootCamp 直接開機,或者在 VMWare/Parallels 內執行 Windows 都可適用。

請注意,你也可以在 KeyRemap4MacBook 中達到類似 SharpKeys 的功能,但需要把按鍵對應到 VK_LAZY_OPTION_L 以延遲發送,否則在 Windows 內會有異常的效果。但這個延遲時間可能不足,使用上仍可能會碰到一些小問題,不如使用 SharpKeys 簡便。

1 則留言:

  1. 進入SharpKeys之後要點甚麼才能下載呢

    回覆刪除