SharpHook: Getting false positives for 'Alt' key.

We have a piece of software that tries to listen to certain key combinations. When we use the ‘Alt’ key in version 5.x, it sometimes gets stuck in the ‘pressed’ state and stay that way until we manually press it again. This issue didn’t happen with version 4.2.x.

        private void OnKeyPressed(object? sender, KeyboardHookEventArgs args)
        {
            // [...]
            if ((args.RawEvent.Mask & ModifierMask.Alt) > 0)
            {
                // this gets here even when alt is not pressed down.
            }

Our full implementation of the class is here.

I have tried to comment out pieces of code to get to the bare minimum and the false positives appear to stay there. Then when I ‘spam’ the alt key to kind of unstick it, keybinds work as expected.

About this issue

  • Original URL
  • State: closed
  • Created 10 months ago
  • Comments: 16 (8 by maintainers)

Most upvoted comments

@TolikPylypchuk Hi, thanks for checking this out! I couldn’t check earlier but I just updated and tried this scenario again. Everything appears to be working now! I am glad you figured it out.

Thank you!

This makes sense @TolikPylypchuk and not a problem as long as you’re aware of it. Great work by the way!

Can confirm this bug on Windows 11! Also did not happen with v4.2 - only bugged in v5. 😦

Thanks for taking the time to look into this. I will get you the logs when I next see the problem.

We are currently only supporting Windows. We had a goal of cross platform at some point, but that goal keeps moving as we always struggle to find cross platform solutions.