Takayama Fumihiko | Email: <tekezo@pqrs.org> | Google+

private.xml Reference Manual

table of contents

Example

A simple example of private.xml.

<?xml version="1.0"?>
<root>
  <item>
    <name>Swap Space and Tab</name>
    <identifier>private.swap_space_and_tab</identifier>
    <autogen>--KeyToKey-- KeyCode::SPACE, KeyCode::TAB</autogen>
    <autogen>--KeyToKey-- KeyCode::TAB, KeyCode::SPACE</autogen>
  </item>

  <item>
    <name>Swap Return and Escape</name>
    <identifier>private.swap_return_and_escape</identifier>
    <autogen>--KeyToKey-- KeyCode::RETURN, KeyCode::ESCAPE</autogen>
    <autogen>--KeyToKey-- KeyCode::ESCAPE, KeyCode::RETURN</autogen>
  </item>
</root>
Then, after reloading XML, two settings are added. xml_basic.png

Samples of <autogen>

There are a lot of samples of <autogen> in "Samples for KeyRemap4MacBook Developer" (at a bottom of KeyRemap4MacBook Prefs).
samples.xml
samples_for_developer.png

In addition, all installed setting is described in checkbox.xml.
It's a good example of <autogen>.
(Note: You cannot use "#include" in private.xml. Unfold all settings to private.xml.)

Basic

Definition

You can define a new setting by <item> tag.
<?xml version="1.0"?>
<root>

  <item>
    <name>Name of Setting</name>
    <appendix>Optional Description of Setting</appendix>
    <identifier>Unique Identifier of Setting</identifier>
    <autogen>Behavior Definition</autogen>
    <autogen>Behavior Definition</autogen>
  </item>

  <item>...</item>

  <item>...</item>
</root>
Please define <name>, <identifier>, <autogen> tags under <item>.
<name>
<appendix>
This value is used in PreferencePane.
<identifier> You need to specify a unique value. We recommend you to add a "private." prefix to your identifier. It prevents conflicts with preset identifiers.
<autogen> Define your settings. For example, --KeyToKey--, --PointingButtonToKey--.

List of KeyCode, ConsumerKeyCode, PointingButton

--KeyToKey-- Syntax

  1. Plain:
    This autogen changes space key to tab key.
    <autogen>--KeyToKey-- KeyCode::SPACE, KeyCode::TAB</autogen>
    
  2. Modifier+Key to Key:
    This autogen changes "left control+space key" to tab key.
    <autogen>--KeyToKey--
      KeyCode::SPACE, ModifierFlag::CONTROL_L,
      KeyCode::TAB
    </autogen>
    
  3. Modifier+Key to Modifier+Key:
    This autogen changes "left control+space key" to "left control+tab key".
    <autogen>--KeyToKey--
      KeyCode::SPACE, ModifierFlag::CONTROL_L,
      KeyCode::TAB,   ModifierFlag::CONTROL_L
    </autogen>
    
  4. Multiple Modifier:
    Use "|" to specify multiple modifiers.
    This autogen changes "left control+fn+space key" to tab key.
    <autogen>--KeyToKey--
      KeyCode::SPACE, ModifierFlag::CONTROL_L | ModifierFlag::FN,
      KeyCode::TAB
    </autogen>
    
  5. ModifierFlag::NONE
    If you want to change key behavior only when specific modifiers are pressed, use ModifierFlag::NONE.
    This autogen changes "fn+space key" to tab key and retain other modifier combinations+space key behavior.
    For example, control+fn+space key acts as control+fn+space. (not control+tab)
    <autogen>--KeyToKey--
      KeyCode::SPACE, ModifierFlag::FN | ModifierFlag::NONE,
      KeyCode::TAB
    </autogen>
    
  6. Change to Multiple Keys
    This autogen changes space key to tab,return key.
    <autogen>--KeyToKey--
      KeyCode::SPACE,
      KeyCode::TAB, KeyCode::RETURN
    </autogen>
    

Application Specific Setting

Example

You can define settings which are effective on specific applications only.
Add <only> or <not> tag to your <item>.

This private.xml exchanges space key and tab key on Safari.
<?xml version="1.0"?>
<root>
  <item>
    <name>Swap Space and Tab</name>
    <identifier>private.app_safari_swap_space_and_tab</identifier>
    <only>SAFARI</only>
    <autogen>--KeyToKey-- KeyCode::SPACE, KeyCode::TAB</autogen>
    <autogen>--KeyToKey-- KeyCode::TAB, KeyCode::SPACE</autogen>
  </item>
</root>

Steps to define Application Specific Setting

At first, examine a bundle identifier of target application.
  1. Launch EventViewer from a menu.
    eventviewer-menu.png

  2. See "Current Application" of EventViewer.
    This value is changed when you change the current application.
    Change the current application to target application. Then press "copy to pasteboard" button.
    You can paste this information to text area.
    eventviewer.png
Then, add an application definition to your private.xml.
  1. Add <appdef> to your private.xml.
    <appname> is a name of application which you use in <only> filter.
    Write the bundle identifier into <equal>.
    <?xml version="1.0"?>
    <root>
      <appdef>
        <appname>APPSTORE</appname>
        <equal>com.apple.appstore</equal>
      </appdef>
    </root>
    
  2. Then, you can use <only>APPSTORE</only> in private.xml.
    <?xml version="1.0"?>
    <root>
      <appdef>
        <appname>APPSTORE</appname>
        <equal>com.apple.appstore</equal>
      </appdef>
    
      <item>
        <name>Space to Tab on App Store.app</name>
        <identifier>private.appdef</identifier>
        <only>APPSTORE</only>
        <autogen>--KeyToKey-- KeyCode::SPACE, KeyCode::TAB</autogen>
      </item>
    </root>
    

Presets of Application Definition

KeyRemap4MacBook provides various application definitions.
You can use these apps without <appdef> in private.xml.
You can also overwrite existent application definitions by private.xml.
If you overwrite TERMINAL definition as follows, <only>TERMINAL</only> is effective on Apple's Terminal.app only. (not iTerm2 and other terminal apps.)
<?xml version="1.0"?>
<root>
  <appdef>
    <appname>TERMINAL</appname>
    <equal>com.apple.Terminal</equal>
  </appdef>
</root>

Device Specific Setting

Example

You can define settings which are effective on specific device only.
Add <device_only> or <device_not> tag to your <item>.

This private.xml turns scroll wheel off on Magic Mouse.
<?xml version="1.0"?>
<root>
  <item>
    <name>Disable ScrollWheel on Magic Mouse</name>
    <identifier>private.dropscrollwheel_0x05ac_0x030d</identifier>
    <device_only>DeviceVendor::APPLE_COMPUTER,DeviceProduct::MAGIC_MOUSE</device_only>
    <autogen>--DropScrollWheel--</autogen>
  </item>
</root>

Steps to define Device Specific Setting

At first, examine Vendor ID and Product ID of a target device.
  1. Launch System Information.app (System Profiler.app in Snow Leopard).
    You can launch System Information.app from the menu by clicking Apple mark while pressing Option key.
    option-apple.png

  2. Examine VendorID and ProductID of the device.
    system-profiler.png
Then, add an device definition to your private.xml.
  1. Add <devicevendordef> and <deviceproductdef> to your private.xml.
    <?xml version="1.0"?>
    <root>
      <devicevendordef>
        <vendorname>HEWLETT_PACKARD</vendorname>
        <vendorid>0x03f0</vendorid>
      </devicevendordef>
    
      <deviceproductdef>
        <productname>MY_HP_KEYBOARD</productname>
        <productid>0x0224</productid>
      </deviceproductdef>
    </root>
    
  2. Then, you can use <device_only> in private.xml.
    <?xml version="1.0"?>
    <root>
      <devicevendordef>
        <vendorname>HEWLETT_PACKARD</vendorname>
        <vendorid>0x03f0</vendorid>
      </devicevendordef>
    
      <deviceproductdef>
        <productname>MY_HP_KEYBOARD</productname>
        <productid>0x0224</productid>
      </deviceproductdef>
    
      <item>
        <name>Space to Tab in MY_HP_KEYBOARD</name>
        <identifier>private.deviceproductdef</identifier>
        <device_only>DeviceVendor::HEWLETT_PACKARD, DeviceProduct::MY_HP_KEYBOARD</device_only>
        <autogen>--KeyToKey-- KeyCode::SPACE, KeyCode::TAB</autogen>
      </item>
    
    </root>
    

Presets of Device Definition

KeyRemap4MacBook provides various device definitions.
You can use these apps without <devicevendordef>, <deviceproductdef> in private.xml.
You can also overwrite existent device definitions by private.xml.
Date: 2012-02-21 15:35 (UTC)