Tech

A Workaround for simultaneous key presses in OSX

October 5, 2015
--
User avatar
Adrian Perez
@blackxored

This had been bugging for a long time, as has to many users before: OSX doesn't seem to register simultaneous keypresses the way that Windows works, having many users wondering about N-key Rollover and whatnot.

I decided to dig into it, cave around the forums, Google Groups and every available documentation, and the solution finally came with the aid of a software I was already using: Karabiner. I don't remember exactly where I saw a discussion that led to this (re)discovery (which proves how hidden it was), I thought sharing is caring 😂.

Karabiner is an excellent software (you've probably seen me tweet about its Vim-mode settings). Don't worry, I plan to take a look at the developer settings I have in a future post. But this particular issue has been bugging me forever (no pun intended, although Apple, really, is it a bug or a feature?), hence in this one let's take a look at how to make the system respond accordingly when pressing two keys at the same time, like this:

dsdsdsdsdsdsdsdsdsdsdsdsdsdsdsdsdsdsdsdsds

In case you're a bit lost, the default behavior is:

sddddddddddddddddddddddddddddddddddddd

But we're about to "fix" that. I opened the private.xml file (under the Misc & Uninstall section on Karabiner) and added the following (irrelevant parts omitted for clarity).

<?xml version="1.0"?>
<root>
      <list>
        <item>
          <name>Simultaneous Mode</name>
          <appendix>This mode fixes OSX key repeat behavior to allow simultaneous key presses</appendix>

          <item>
            <name>S + D</name>
            <identifier>simulatenous.s_d</identifier>

            <autogen>
              __SimultaneousKeyPresses__

              @begin
              KeyCode::S, KeyCode::D
              @end

              @begin
              KeyCode::S, KeyCode::D
              @end

              Option::SIMULTANEOUSKEYPRESSES_STRICT_KEY_ORDER,
            </autogen>
            <autogen>
              __SimultaneousKeyPresses__

              @begin
              KeyCode::D, KeyCode::S,
              @end

              @begin
              KeyCode::D, KeyCode::S,
              @end

              Option::SIMULTANEOUSKEYPRESSES_STRICT_KEY_ORDER,
            </autogen>
          </item>
        </item>
    </list>
</root>

Then reload the XML, check the menu item under Simultaneous Mode, and that's it! You do need to add all keys (or the ones you use, I don't use all in combination), since I haven't figured how to programmatically add them if it were to be possible to begin with, so it's rinse and repeat for now. Nevertheless, this is a nice workaround; which I've tested both on Yosemite and El Capitan.

Finally, if you need to figure out which are the keycodes corresponding to the keys you want to add to this file, you can open the Event Viewer (also under the same section), and just press the keys, you should see something like the following:

karabiner

I hope that helped you, you can test it right away on my comments box below, just make sure not to hit Post 🙈.

~ EOF ~

Craftmanship Journey
λ
Software Engineering Blog

Stay in Touch


© 2020 Adrian Perez