如何使用 if-else 定义热键?
How to define hot keys using if-else?
我想针对不同的热键按下执行两种方法,检查 if-else 按下了什么键
如何使用 this 示例执行此操作?
我是这样用的:
private static void Main()
{
HotKeyManager.RegisterHotKey(key: Keys.G, modifiers: HotKeyEventArgs.KeyModifiers.Alt);
HotKeyManager.HotKeyPressed += new EventHandler<HotKeyEventArgs>(HotKeyManager_HotKeyPressed);
Console.ReadLine();
}
private static void HotKeyManager_HotKeyPressed(object sender, HotKeyEventArgs e)
{
Console.WriteLine("Example HotKeys Activate");
}
如何使用不同的热键执行两个不同的事件?
您需要注册所有热键,然后才能使用 HotKeyEventArgs
:
的 Key
和 Modifiers
属性
private static void Main()
{
HotKeyManager.RegisterHotKey(key: Keys.G, modifiers: HotKeyEventArgs.KeyModifiers.Alt);
HotKeyManager.RegisterHotKey(key: Keys.P, modifiers: HotKeyEventArgs.KeyModifiers.Alt);
HotKeyManager.HotKeyPressed += new EventHandler<HotKeyEventArgs>(HotKeyManager_HotKeyPressed);
Console.ReadLine();
}
private static void HotKeyManager_HotKeyPressed(object sender, HotKeyEventArgs e)
{
if (e.Key == Keys.G && e.Modifiers == HotKeyEventArgs.KeyModifiers.Alt)
OnPressedAltG();
else if (e.Key == Keys.P && e.Modifiers == HotKeyEventArgs.KeyModifiers.Alt)
OnPressedAltP();
}
private static void OnPressedAltG()
{
Console.WriteLine("Alt+G was pressed.");
}
private static void OnPressedAltP()
{
Console.WriteLine("Alt+P was pressed.");
}
我想针对不同的热键按下执行两种方法,检查 if-else 按下了什么键
如何使用 this 示例执行此操作?
我是这样用的:
private static void Main()
{
HotKeyManager.RegisterHotKey(key: Keys.G, modifiers: HotKeyEventArgs.KeyModifiers.Alt);
HotKeyManager.HotKeyPressed += new EventHandler<HotKeyEventArgs>(HotKeyManager_HotKeyPressed);
Console.ReadLine();
}
private static void HotKeyManager_HotKeyPressed(object sender, HotKeyEventArgs e)
{
Console.WriteLine("Example HotKeys Activate");
}
如何使用不同的热键执行两个不同的事件?
您需要注册所有热键,然后才能使用 HotKeyEventArgs
:
Key
和 Modifiers
属性
private static void Main()
{
HotKeyManager.RegisterHotKey(key: Keys.G, modifiers: HotKeyEventArgs.KeyModifiers.Alt);
HotKeyManager.RegisterHotKey(key: Keys.P, modifiers: HotKeyEventArgs.KeyModifiers.Alt);
HotKeyManager.HotKeyPressed += new EventHandler<HotKeyEventArgs>(HotKeyManager_HotKeyPressed);
Console.ReadLine();
}
private static void HotKeyManager_HotKeyPressed(object sender, HotKeyEventArgs e)
{
if (e.Key == Keys.G && e.Modifiers == HotKeyEventArgs.KeyModifiers.Alt)
OnPressedAltG();
else if (e.Key == Keys.P && e.Modifiers == HotKeyEventArgs.KeyModifiers.Alt)
OnPressedAltP();
}
private static void OnPressedAltG()
{
Console.WriteLine("Alt+G was pressed.");
}
private static void OnPressedAltP()
{
Console.WriteLine("Alt+P was pressed.");
}