C#C
C#3y ago
Owen

❔ Issue with GlobalMouseKeyHook / Global Hotkeys.

I am using: https://github.com/gmamaladze/globalmousekeyhook in one of my C# console applications to receive keypresses when the console is out of focus.
This works in one of my applications - but when attempting to use the same code in a new project, the key presses are not detected at all.

Not sure what the problem could be here. Any ideas?
Here's the implementation i'm using in both programs.
    using Gma.System.MouseKeyHook;
    
    public class CreateHotkeyEvent
    {
        public static void Do()
        {
            Hook.GlobalEvents().KeyPress += (sender, e) =>
            {
                if (e.KeyChar == ')')
                {
                    Console.WriteLine("stop");
                    ConsoleExtensions.ChangeRunningState();
                }
                else if(e.KeyChar == '(')
                {
                    Console.WriteLine("hide");
                    ConsoleExtensions.ShowHideWindow();
                }
            };
        }
    }
GitHub
This library allows you to tap keyboard and mouse, detect and record their activity even when an application is inactive and runs in background. - GitHub - gmamaladze/globalmousekeyhook: This libra...
Was this page helpful?