gpt4 book ai didi

c# - 在控制台中检测 Ctrl + S

转载 作者:太空宇宙 更新时间:2023-11-03 15:14:42 24 4
gpt4 key购买 nike

我正在开发一个控制台应用程序,我需要在其中检测多个热键,例如 Ctrl+NCtrl+ OCtrl+S。下面是我用来识别这些热键的部分代码:

ConsoleKeyInfo input = Console.ReadKey(true);

if (input.Modifiers == ConsoleModifiers.Control)
{
if (input.Key == ConsoleKey.N)
{
// ...
}
else if (input.Key == ConsoleKey.O)
{
// ...
}
else if (input.Key == ConsoleKey.S)
{
//...
}
}

上面的代码对于 Ctrl+NCtrl+O 没有任何问题。但是,我无法让它为 Ctrl+S 工作。在做了一些快速测试后,我发现按 Ctrl+S 甚至没有做任何事情(这意味着程序仍在等待用户键入内容)。

此问题仅在 Ctrl+S 时出现。对任何其他修饰符(例如 Shift)和键(NO 等)使用一些简单的 if 语句) 工作正常。

为什么会这样? Ctrl+S 组合是否有特殊含义?有可能使这项工作吗?如果是,如何?

最佳答案

protected override  bool  ProcessCmdKey(ref Message msg, Keys keyData)
{
if (msg.Msg == 256)
{
//if the user pressed control + s
if (keyData == (Keys.Control | Keys.S))
{

}
//if the user pressed control + o
else if (keyData == (Keys.Control | Keys.O))
{

}
//if the user pressed control + n
else if (keyData == (Keys.Control | Keys.N))
{

}
}
return base.ProcessCmdKey(ref msg, keyData);
}

关于c# - 在控制台中检测 Ctrl + S,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39476157/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com