finkrer / KeyboardChatteringFix-Linux

A tool for blocking mechanical keyboard chattering on Linux
MIT License
107 stars 15 forks source link

Cancelling double letters, even when they are separated #9

Open CarlosRuiz-globalqss opened 1 month ago

CarlosRuiz-globalqss commented 1 month ago

Firstly I must say that I am a very fast typist.

So, the program is cancelling double letters when I type too fast. For example "cancelling" turns out as "canceling", and "letters" turns out as "leters". But that's understandable, if my second typing happens faster than the threshold.

The problem that I think it can be preventable is that the second letter is also cancelled even when is separated by another keystroke.

For example "even" becomes "evn", or "the elder" turns out as "the lder".

I don't know much about python to solve it myself, but I guess it can be something like, on every keystroke if the previous keystroke is different then cancel the threshold.

finkrer commented 1 month ago

Hi @CarlosRuiz-globalqss. That's a good point. Unfortunately, in my experience, being smart with keystrokes, especially when it comes to taking into accout speed or duration, usually backfires somewhere. Here, we have to be smart by necessity, and it will never work perfectly.

You could check the last key, sure. The issue is that, when typing fast, you can likely type the next letter in-between chatters, and the chatter will get through. As a fast typer, your presses likely overlap, so it's hard to say what's going on.

In any case, if you want to try it, it should be easy. https://github.com/finkrer/KeyboardChatteringFix-Linux/blob/2e610af1a0d2027f61d2807945e79387900a1dd6/src/filtering.py#L57-L58 Here, add

_last_key_code = None

https://github.com/finkrer/KeyboardChatteringFix-Linux/blob/2e610af1a0d2027f61d2807945e79387900a1dd6/src/filtering.py#L47 Then here, change the condition to

if prev is None or now - prev > threshold * 1E3 or _last_key_code != event.code:

https://github.com/finkrer/KeyboardChatteringFix-Linux/blob/2e610af1a0d2027f61d2807945e79387900a1dd6/src/filtering.py#L49 And after this line, add

_last_key_code = event.code

This should work, you can try it for yourself and report if there are any issues. Also, you could try playing with the threshold value if you are typing very fast.

CarlosRuiz-globalqss commented 1 month ago

Thanks @finkrer - opened pull request https://github.com/finkrer/KeyboardChatteringFix-Linux/pull/10

Until now it seems working fine for the second case, the first case "letter -> leter" sounds very difficult to fix, as you advice the only option here would be to play with the threshold.

Thanks for your help, learnt a bit of python today :-)