Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Typing "zu" sometimes becomes "zuzu" #53

Closed
Dunedan opened this issue Nov 29, 2017 · 6 comments · Fixed by #62
Closed

Typing "zu" sometimes becomes "zuzu" #53

Dunedan opened this issue Nov 29, 2017 · 6 comments · Fixed by #62

Comments

@Dunedan
Copy link
Contributor

Dunedan commented Nov 29, 2017

I've a very strange bug, I'm encountering pretty irregularly and I can't actively reproduce it, but it happens from time to time that when I type the German word "zu" instead "zuzu" appears on the screen. I haven't encountered this problem with any other combination of characters so far.

@roadrunner2
Copy link
Contributor

This does sound strange. My first thought is that this is some form of double-key-event generation that I've encountered on that keyboard: specifically if I pressed a certain key (and in my case it only happened on one key) on the side instead of in the middle, then it would generate an event both when pressed and when released - try playing around with pressing the z and u keys on the various sides and see if you can get a double event. Now, I would normally think that you would then get things like zzu, zuu, or even zzuu, not zuzu, but the latter is possible if z is pressed, u is pressed, then z released, and finally u released.

Also, try setting the debug parameter to 0x100:

  echo 0x100 | sudo tee /sys/module/applespi/parameters/debug

and then show what events are reported when this happens.

@Dunedan
Copy link
Contributor Author

Dunedan commented Feb 28, 2018

So, finally I managed to find a way to reproduce it. It's related to hitting the allowed maximum number of keys pressed in parallel. That limit seems to be dynamic, depending on which keys are pressed. E.g. for pressing qwertyu it's 6, while it's only 2 for pressing <space>gh (I realized that zu is a bad example as I've a German keyboard, where z and y are switched). If you press more keys than this limit in parallel the keyboard emits an unusual event (containing 01 in all fields where usually the key codes would be). If you then lift the fingers up in a any order you don't get the desired output.

Easiest way to reproduce:

  1. disable key repeating (just to make it easier to see)
  2. press <space> and keep it pressed
  3. press g and keep it pressed
  4. press h and keep it pressed
  5. lift the finger from <space>
  6. lift the finger from g
  7. lift the finger from h

Expected output: <space>gh
Actual output: <space>g<space>gh

Attached is a debug log of pressing "<space>gh" which causes "<space>g<space>gh" to appear: key-press-bug.txt

roadrunner2 referenced this issue in roadrunner2/macbook12-spi-driver Mar 1, 2018
The keyboard sends an all keys = 1 keyboard event when an overflow is
detected, which we need to detect and ignore.

This fixes #53.
@roadrunner2
Copy link
Contributor

Excellent debugging work! Thanks. Easy to reproduce now.

So it looks like the solution is just to ignore these rollover-overflow keyboard messages. I just pushed an update to my fork - if you can try that out and confirm it fixes things, I'll send the pull request.

Btw., while on the topic of key rollover, @cb22 you have a note in the README saying that key rollover does not work properly - can you elaborate? I'm not aware of any issues or missing functionality (especially with this issue here fixed).

@Dunedan
Copy link
Contributor Author

Dunedan commented Mar 1, 2018

Thanks for the quick fix. 👍

It's already a significant improvement, but a small annoyance remains: With enabled key repeating its output isn't as expected. Pressing and holding <space>gh in order I'd ideally expect multiple spaces, followed by multiple g's, followed by multiple h's or (as that's not possible with the max rollover apparently) multiple spaces, multiple g's, where the g's stop to get printed as soon as I press h. Instead it continues to print g's even after pressing h and stops printing g's only once I remove one of the fingers (e.g. the one on space).

@roadrunner2
Copy link
Contributor

Yeah, I was thinking about this too after my last update. The problem is this: disabling of autorepeat only happens on another key-event, and there is no clean way to signal this condition. The best I've been able to come up with is to send a dummy key down/up event for the KEY_UNKNOWN key. This appears to work - see my latest repo update. However, I'm not sure how kosher this is and whether it'll survive scrutiny when we try to upstream this driver.

@Dunedan
Copy link
Contributor Author

Dunedan commented Mar 3, 2018

I did a check what Apple does in this situation under macOS, because maybe they have some smart handling for that. Turns out: no, their behavior is exactly the same as with your patch.
Additionally I checked what Linux does with the hid_apple driver on a MacBook Air. Again: Same behavior as with your patch. So I'd say, opening a PR with your existing patch is the most pragmatic solution for this issue.

roadrunner2 referenced this issue in roadrunner2/macbook12-spi-driver Mar 4, 2018
The keyboard sends an all keys = 1 keyboard event when an overflow is
detected, which we need to detect and ignore.

This fixes #53.
roadrunner2 referenced this issue in roadrunner2/macbook12-spi-driver Mar 5, 2018
The keyboard sends an all keys = 1 keyboard event when an overflow is
detected, which we need to detect and ignore.

This fixes #53.
@cb22 cb22 closed this as completed in #62 Mar 14, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants