Owen
Owen
CC#
Created by Owen on 4/20/2023 in #help
❔ 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();
}
};
}
}
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();
}
};
}
}
48 replies