jtroo / kanata

Improve keyboard comfort and usability with advanced customization
GNU Lesser General Public License v3.0
2.33k stars 115 forks source link

Modifier keys (meta/windows/super, alt, shift, ctrl) can sometimes get stuck #188

Closed jtroo closed 1 year ago

jtroo commented 1 year ago

Testing hyper-modded keys in a layer:

As I was testing this out, kanata entered a borked state, where:

Any clue what might have happened or something to try to prevent or escape from it in the future?


Also, more usage questions, apologies if I'm getting annoying:

  1. I noticed that with both my AHK solution and with this one that when using the vim-right key (capslock + the letter L), plus Win, instead of (or in addition to) emitting Win + Right (eg for moving the active window to the right), it locks Windows. That is, it fails to override the windows hotkey of Win+L for Lock. Would the interception driver solve this, or running kanata as admin, or something else?

Originally posted by @riotrah in https://github.com/jtroo/kanata/discussions/185#discussioncomment-4142758

jtroo commented 1 year ago

@riotrah I've done some testing on this using configuration with the llhook mechanism.

(defcfg process-unmapped-keys true)

(defsrc 
  7 8 9 0 
  caps
)

(deflayer base 
  _ _ _ _
  (tap-hold-press 200 200 caps (layer-while-held layer))
)

(deflayer layer 
  C-S-A-M-b C-S-A-M-a C-S-A-M-c C-S-A-M-k
  _
)

I haven't been able to create any strange or incorrect behaviour so far. Are there specific key combinations that are triggering the bug?

Additional reproduction info would be great 🙂

riotrah commented 1 year ago

I've changed nothing about my computer usage, yet I haven't actually repro'd it since that first day I was setting it up 🤷.

My computer happened to be a lil sluggish as I was rendering a bunch of audio files at the time. Perhaps there's some mistiming issue or something when under load? Couldn't begin to guess.

riotrah commented 1 year ago

So I perused kmonads repo for tips on running at startup. I couldn't find much relevant info I guess because keyword search is hard in popular projects, but I did see a couple of issues about stuck keys.

I wish I copied the urls but I didn't and couldn't find them again easily. However, it looks like there are a couple of cases that might trigger a stuck key , modifier or otherwise.

  1. Having the modifier keys held down while Kanata starts, or perhaps lrlds

    • because I'm addicted to my caps lock hyper key behavior, I might have had AHK running while I was testing out kanata
      • probably not though as that probably would have made testing out my Kanata config nigh impossible
    • still, I might have had the keys physically held down or something
  2. Having Kanata emit a modifier before Windows locks or sleeps or something, and then reactivating windows, thereby keeping the press - because no release event was emitted, the keys stayed held down

    • not sure if Kanata is prey to the same issues with the mechanism that monad uses, however, I think the LLhook is the same?
jtroo commented 1 year ago

Just for some context, and for visibility, I'll repeat something I mentioned in a different issue. In my perusing, others have encountered a similar issue without using kanata. I've seen someone say it's happened to them when using only AHK; they weren't a kanata user.

So it seems like the issue is not directly related to kanata; it's something to do with the hook mechanism and/or SendInput.

riotrah commented 1 year ago

I'm not familiar with win32 APIs (though at this point I suppose it wouldn't hurt to learn), so to clarify:

  1. "the hook"/llhook refers to this windows keyboard "hook" - which I gather from its mentions in AHK, Kanata, powertoys and kmonad, and from the intense frustration many have with interception which suggests it's the only other real alternative, is the only API with which one can implement really "robust" key remapping on windows

  2. I'm not at my PC but SendInput is the AHK flag to utilize the hook as opposed to some other method, correct?

That all makes sense. I suppose I could have just as easily googled that.

And it increasingly appears that in the similar cases seen so far, AHK might be the thing responsible for setting these pressed states as far as the hook is concerned. Then somehow Kanata and AHK start overlapping or conflicting somehow at which point "no one" is able to communicate any subsequent releases to the hook.

I guess what I don't get, is:

  1. Why I'm able to unstick keys in AHK by tapping them again, yet the memorable last time I had this issue, tapping didn't unstick them. Perhaps there was some conflict between the two apps?

  2. If so, I'm wondering why it hasn't happened since. I've been using both at once to great effect, and it's likely many of the same conditions from when things got messed up reoccurred. Certainly the same config is in place 🤔

Either way, I suppose this bug is resolved for now for me. Thanks for the update!

jtroo commented 1 year ago

Let's leave this ticket open for visibility.

For reference: