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

Stuck Keys #33

Open
MartinLichtblau opened this issue Apr 1, 2019 · 8 comments
Open

Stuck Keys #33

MartinLichtblau opened this issue Apr 1, 2019 · 8 comments
Labels
bug Something isn't working

Comments

@MartinLichtblau
Copy link

I have remapped all modifier keys with AHI, for instance Alt is Ctrl now. But too often I get stuck keys, pressumably when pressing multiple modifier keys at the same time.
Could it be that AHI's ability to block inputs is causing this? E.g. when a key is physically released while the input is blocked.

@MartinLichtblau
Copy link
Author

MartinLichtblau commented May 14, 2019

Finally I found the cause of it and a fix for it.
Keys become stuck because the event for key down is called after the key up event and thus the SendKeyEvent fires down although the key is already up and the respective event already fired.
This can happen with such a simple construct:

LAltEvent(state) {
    if(state) {
            AHI.SendKeyEvent(kbdId, lShiftSc, 1)
    } else {
        AHI.SendKeyEvent(kbdId, lShiftSc, 0)
    }
}

This likely happens because both up and down events happen roughly at the same time and AHI handles these events in the wrong order. I guess that thread pooling and calling is responsible for it. You could also say that the keyboard key repeat function is the culprit.
The best indicator I found is that the A_Tickcount for the up and down event is identical.

Therefore the solution is to fire the down event only if the tickcount of the up and down event is different.

LAltEvent(state) {
    static LAltEventDownTime, LAltEventUpTime
    if(state) {
        LAltEventDownTime := A_Tickcount
        if (LAltEventDownTime != LAltEventUpTime) {
            AHI.SendKeyEvent(kbdId, lShiftSc, 1)
        } 
    } else {
        LAltEventUpTime := A_Tickcount
        AHI.SendKeyEvent(kbdId, lShiftSc, 0)
    }
}

@MartinLichtblau
Copy link
Author

@evilC Am I doing something wrong. Or is there a simpler way to fix this? Or have you even already fixed it in a newer release?

@evilC
Copy link
Owner

evilC commented May 14, 2019

Yes, the thread pooling is a matter of concern for me too
Crumbl3d submitted a PR with some code that makes all the callbacks fire in sequence - he currently added it as an option IIRC, but I was planning on making it the default.
It looks like it is yet to be merged...
5dc35cc#diff-a4ebf4dc9a0414115220de3f4d687070L122
If you can compile yourself, fine - if not I will try and make a build for you tonight to see if it solves your issues.
Thanks for doing the legwork on this!

@evilC evilC added the bug Something isn't working label May 14, 2019
@evilC
Copy link
Owner

evilC commented May 14, 2019

I made a test release: https://github.com/evilC/AutoHotInterception/releases/tag/v0.4.0
Notice the extra concurrent param for the subscribe methods. Try setting this to true and see if any issues still repro.

@MartinLichtblau
Copy link
Author

Thank you so much!
The good news is that I can't reproduce the bug, neither with the concurrent param true, false or none at all. I'll try out some more in the next days, but this one looks goog now either way; although I don't know why.
Furthemore the event state value seems to be inverted; now 1 is up and 0 is down.

@evilC
Copy link
Owner

evilC commented May 15, 2019

The good news is that I can't reproduce the bug, neither with the concurrent param true, false or none at all

Hmm, strange. There were quite a lot of other changes and fixes in there - I did actually put some fixes in there for extended chars, it was maybe that...
State inversion has been fixed.
0.4.1 has been released

@MartinLichtblau
Copy link
Author

0.4.1 works fine! Interestingly the first thing I noticed with both new versions is the responsiveness. Typing feels so much smoother now. Before it also had a noticable delay. Don't know why and also don't need to know, but this is a huge improvement for me.

#bug: sending RShift instantly kills my script.

@evilC
Copy link
Owner

evilC commented May 17, 2019

#bug: sending RShift instantly kills my script.

If this is persisting, can you raise another issue please?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants