pqrs-org / Karabiner-archived

Karabiner (KeyRemap4MacBook) is a powerful utility for keyboard customization.
https://pqrs.org/osx/karabiner/
The Unlicense
3.82k stars 311 forks source link

Key press ignored on high cpu load #370

Closed epegzz closed 8 years ago

epegzz commented 9 years ago

Hi :) When my CPU spikes then sometimes keypresses are ignored. This happens for example quite often when editing bigger files in sublime text.

Let's say we have a mapping, that prints 'TEST' when you press the key '1' like this:

<autogen>
  --KeyToKey--
  KeyCode::KEY_1,
  KeyCode::T, KeyCode::E, KeyCode::S, KeyCode::T
</autogen>

Then sometimes you only get EST as a result instead of the full TEST. So the first key press get's ignored.

I am not sure if this is an issue with yosemite (10.10.2) or with Karabiner?

epegzz commented 9 years ago

Here's my private.xml and my keylayout

tekezo commented 9 years ago

Is not it an issue of sublime text? How do I reproduce this issue?

epegzz commented 9 years ago

It happens with all programs. Not sure how to best reproduce this, since it only occurs under high load. Will try to provide a test setup for you :)

epegzz commented 9 years ago

All right, here we go:

<item>
      <name>Ignored keys test</name>
      <identifier>private.ignored_keys_test</identifier>
      <autogen>
        --KeyToKey--
        KeyCode::KEY_1,
        KeyCode::T, KeyCode::E, KeyCode::S, KeyCode::T
      </autogen>
</item>

Put this in your private.xml and activate it.

Now open chrome (or any other browser), open a new tab, click into the url bar and press 1. This should print test. But because url auto completion kicks in the load temporarily increases and then often only the letters est or even st appear in the url bar.

If you cannot reproduce this, try increasing your overall cpu load by giving your computer some heavy task (compiling, benchmarking, ...).

This may not be a problem in Karabiner, but you are probably the one who can tell best if it is or not :)

tekezo commented 9 years ago

I cannot reproduce this issue... Is another apps causes this issue? (eg. TextExpander, other snippets tools)

epegzz commented 9 years ago

I've been quitting all programs now for testing except of the browser (tested with two different browsers). The issue only happens 2 out of 10 times now and only if I press cmd + 't' (for opening a new tab) and then 1 (to write test) consecutively very quickly. But it does still happen. Instead of test only tet gets written. I don't have the most powerful computer (Macbook Air mid 2011), which is probably why it's easy for things like browser url auto completion to cause significant CPU load spikes.

The reason why this bug has a real impact on me on a daily basis is because I created a keyboard layout that is using KeyToKey generated sequences a lot in order to have navigation, number and coding characters accessible on row 1-3 of the keyboard by pressing modifier keys.

I cannot reproduce the issue when opening a new tab and then typing letters normally, like rolling asdf with my left hand. Is there maybe any way to make KeyToKey type generated key sequences a bit slower in order to see if that resolves the issue?

tekezo commented 9 years ago

How about putting wait like this?

https://github.com/tekezo/Karabiner/blob/master/src/core/server/Resources/include/checkbox/samples/virtual_keycodes.xml#L124-L143

You can use KeyCode::VK_WAIT_10MS, 50, 100.

https://github.com/tekezo/Karabiner/blob/master/src/core/server/Resources/include/checkbox/samples/virtual_keycodes.xml#L19-L28

epegzz commented 9 years ago

Oh, awesome, did not know about VK_WAIT, will try that, thx! :)

epegzz commented 9 years ago

Even after adding VK_WAIT_100MS between all keystrokes sometimes keys are ignored :( The characters appears slower than before, but it has no effect on the fact that the issue occurs.

Any idea what else I could try?

tekezo commented 9 years ago

You can extend wait by putting multiple waits. https://github.com/tekezo/Karabiner/blob/master/src/core/server/Resources/include/checkbox/samples/virtual_keycodes.xml#L124-L143

Or sending key code in another layer by JXA might solve this issue. https://github.com/dtinth/JXA-Cookbook/wiki/System-Events