Jul 272015
 

Like this fellow, Steve Losh — better shifting, I’ve been using the wrong shift keys for upper-case letters for as long as I’ve been using a keyboard… as well as some even more egregious errors (right ring finger for ‘p’, right index for ‘b’… the list is nigh endless). Lo, his Karabiner solution:

Arghh!….. It has only been a couple of hours and this is devilishly frustrating!!

<item>
    <name>Use the correct shift keys.</name>
    <identifier>private.correct_shift_keys</identifier>

    <autogen>--KeyToKey-- KeyCode::Q, ModifierFlag::SHIFT_L, KeyCode::VK_NONE</autogen>
    <autogen>--KeyToKey-- KeyCode::W, ModifierFlag::SHIFT_L, KeyCode::VK_NONE</autogen>
    <autogen>--KeyToKey-- KeyCode::E, ModifierFlag::SHIFT_L, KeyCode::VK_NONE</autogen>
    <autogen>--KeyToKey-- KeyCode::R, ModifierFlag::SHIFT_L, KeyCode::VK_NONE</autogen>
    <autogen>--KeyToKey-- KeyCode::T, ModifierFlag::SHIFT_L, KeyCode::VK_NONE</autogen>
    <autogen>--KeyToKey-- KeyCode::A, ModifierFlag::SHIFT_L, KeyCode::VK_NONE</autogen>
    <autogen>--KeyToKey-- KeyCode::S, ModifierFlag::SHIFT_L, KeyCode::VK_NONE</autogen>
    <autogen>--KeyToKey-- KeyCode::D, ModifierFlag::SHIFT_L, KeyCode::VK_NONE</autogen>
    <autogen>--KeyToKey-- KeyCode::F, ModifierFlag::SHIFT_L, KeyCode::VK_NONE</autogen>
    <autogen>--KeyToKey-- KeyCode::G, ModifierFlag::SHIFT_L, KeyCode::VK_NONE</autogen>
    <autogen>--KeyToKey-- KeyCode::Z, ModifierFlag::SHIFT_L, KeyCode::VK_NONE</autogen>
    <autogen>--KeyToKey-- KeyCode::X, ModifierFlag::SHIFT_L, KeyCode::VK_NONE</autogen>
    <autogen>--KeyToKey-- KeyCode::C, ModifierFlag::SHIFT_L, KeyCode::VK_NONE</autogen>
    <autogen>--KeyToKey-- KeyCode::V, ModifierFlag::SHIFT_L, KeyCode::VK_NONE</autogen>

    <autogen>--KeyToKey-- KeyCode::Y, ModifierFlag::SHIFT_R, KeyCode::VK_NONE</autogen>
    <autogen>--KeyToKey-- KeyCode::U, ModifierFlag::SHIFT_R, KeyCode::VK_NONE</autogen>
    <autogen>--KeyToKey-- KeyCode::I, ModifierFlag::SHIFT_R, KeyCode::VK_NONE</autogen>
    <autogen>--KeyToKey-- KeyCode::O, ModifierFlag::SHIFT_R, KeyCode::VK_NONE</autogen>
    <autogen>--KeyToKey-- KeyCode::P, ModifierFlag::SHIFT_R, KeyCode::VK_NONE</autogen>
    <autogen>--KeyToKey-- KeyCode::H, ModifierFlag::SHIFT_R, KeyCode::VK_NONE</autogen>
    <autogen>--KeyToKey-- KeyCode::J, ModifierFlag::SHIFT_R, KeyCode::VK_NONE</autogen>
    <autogen>--KeyToKey-- KeyCode::K, ModifierFlag::SHIFT_R, KeyCode::VK_NONE</autogen>
    <autogen>--KeyToKey-- KeyCode::L, ModifierFlag::SHIFT_R, KeyCode::VK_NONE</autogen>
    <autogen>--KeyToKey-- KeyCode::SEMICOLON, ModifierFlag::SHIFT_R, KeyCode::VK_NONE</autogen>
    <autogen>--KeyToKey-- KeyCode::N, ModifierFlag::SHIFT_R, KeyCode::VK_NONE</autogen>
    <autogen>--KeyToKey-- KeyCode::M, ModifierFlag::SHIFT_R, KeyCode::VK_NONE</autogen>
    <autogen>--KeyToKey-- KeyCode::COMMA, ModifierFlag::SHIFT_R, KeyCode::VK_NONE</autogen>
    <autogen>--KeyToKey-- KeyCode::DOT,   ModifierFlag::SHIFT_R, KeyCode::VK_NONE</autogen>
    <autogen>--KeyToKey-- KeyCode::QUOTE, ModifierFlag::SHIFT_R, KeyCode::VK_NONE</autogen>
</item>
Jul 232015
 

Apparently low-level keybindings in OS X used to be managed through

~/Library/KeyBindings/DefaultKeyBinding.dict

which did not exist on this 10.10.4 system. So after having created it and added

{
/* Context Menu */
"\U0x3fc" = "rightMouseDown:"; /* Fun-C */
"^;" = "rightMouseDown:"; /* Ctrl-; */

/* Vim movement while Ctrl key down */
"^h" = ("moveLeft:");
"^j" = ("moveDown:");
"^k" = ("moveUp:");
"^l" = ("moveRight:");

}

it did, of course, not work.

Googling around a bit, I found Karabiner (a powerful and stable keyboard customizer for OS X), and this seems to be able to do the trick perfectly. So, editing ~/Library/Application Support/Karabiner/private.xmlto include:

<?xml version="1.0"?>
<root>
    <item>
            <name>VIM HJKL</name>
            <identifier>private.vim_hjkl</identifier>
            <autogen>
            __KeyToKey__
                KeyCode::H, ModifierFlag::FN,
                KeyCode::CURSOR_LEFT
            </autogen>
            <autogen>
                __KeyToKey__
                KeyCode::J, ModifierFlag::FN,
                KeyCode::CURSOR_DOWN
            </autogen>
            <autogen>
            __KeyToKey__
                KeyCode::K, ModifierFlag::FN,
                KeyCode::CURSOR_UP
            </autogen>
            <autogen>
            __KeyToKey__
                KeyCode::L, ModifierFlag::FN,
                KeyCode::CURSOR_RIGHT
            </autogen>
    </item>
    <item>
        <name>kybd control click</name>
        <identifier>private.keybd_to_control_click</identifier>
        <autogen>
            __KeyToKey__
            KeyCode::C, ModifierFlag::FN,
            KeyCode::VK_MOUSEKEY_BUTTON_RIGHT
        </autogen>
    </item>
</root>

I have two very simple sets of keybindings available to me under Karibiner. Fn+H thru L gives me VIM movement _in any app_, and Fn+c gives me access to contextual menus without the effort of right/control clicking and visual item in OS X.

Karabiner key code data is at https://github.com/tekezo/Karabiner/blob/master/src/bridge/generator/keycode/data/KeyCode.data

OS X keycodes can be gotten fromevents.h,, thus:

$ grep '^ *kVK' /System/Library/Frameworks/Carbon.framework/Versions/A/Frameworks/HIToolbox.framework/Versions/A/Headers/Events.h|tr -d ,|while read x y z;do printf '%d %s %s\n' $z $z ${x#kVK_};done|sort -n

lists them all:

Lovely jubly!

Jul 222015
 

For the longest time I have had caps lock set to “no action” in System Preferences >> Keyboard>> Modifier Keys:

caps-lock-no-action

 

But recently I’ve been playing with Vim (and also finally getting around to learning how to touch type) a little more now that I have some time on my hands, and decided that I needed an escape key that wasn’t such a PITA to get to without risking breaking my left pinkie. Enter Karibiner
 

Karabiner bindings are stored in  ~/Library/Application Support/Karabiner/private.xmlthe syntax of which is pretty easy to follow, and so I have entry in this file that maps caps lock to escape on the one hand, and also as a “hyper” modifier key when pressed in conjunction with certain other keys. The “code” for this is”
 

    <!--    the "hyper key"
           caps locks mapped to escape;
           used as a super modifier when when pressed in conjunction with other keys.
           keys modified with hyper to perform specic actions definied in:
           ~/Library/Application Support/Karabiner/private.xml
           ~/.hammerspoon/init.lua
           or Keyboard Maestro
           initial mapping of caps lock to F19 done in seil.appendix
   -->
    <item>
            <name>F19 to F19</name>
            <appendix>(F19 to Hyper (ctrl+shift+cmd+opt) + F19 Only, send escape)</appendix>
            <identifier>private.f192f19_escape</identifier>
            <autogen>
                --KeyOverlaidModifier--
                KeyCode::F19,
                KeyCode::COMMAND_L,
                ModifierFlag::OPTION_L | ModifierFlag::SHIFT_L | ModifierFlag::CONTROL_L,
                KeyCode::ESCAPE
            </autogen>
        </item>

 

But, apparently, the caps lock key is a “special” key— at least on Macbook Pro keyboards, and some additional configuration needs be done before entries to Karabiner’s private.xml will take effect. The fundamental new mapping of caps lock is therefore done in seil  (a “utility for the caps lock key and some international keys in PC keyboards.”):

seil-mapping-caps-lock

 

Here it is mapped to OS X character code 80 (the F19 key). A complete list of OS X key codes can be seen by executing:
 

grep '^ *kVK’ /System/Library/Frameworks/Carbon.framework/Versions/A/Frameworks/HIToolbox.framework/Versions/A/Headers/Events.h|tr -d ,|while read x y z;do printf '%d %s %s\n' $z $z ${x#kVK_};done|sort -n

Social Widgets powered by AB-WebLog.com.