当按下ALT时,Keys.Numpad0作为Keys.System进入

时间:2017-03-07 17:42:04

标签: c# wpf

我正在尝试通过ALT + 9检测ALT + 1的热键,但是当按下ALT时,键将作为Key.System进入。当按下CTRL + NumPad0时,它的键是Key.NumPad0,这是正确的。

private void MainWindow_PreviewKeyDown(object sender, KeyEventArgs e)
{
    bool isAlt = Keyboard.IsKeyDown(Key.LeftAlt) || Keyboard.IsKeyDown(Key.RightAlt);
    bool isCtrl = Keyboard.IsKeyDown(Key.LeftCtrl) || Keyboard.IsKeyDown(Key.RightCtrl);

    string ctrlMod = string.Empty;

    if (isAlt)
    {
        ctrlMod = "alt + " + e.Key.ToString();
    }

    if (isCtrl)
    {
        ctrlMod = "ctrl + " + e.Key.ToString();
    }

    Debug.WriteLine("Key is " + ctrlMod);
}

ALT + NumPad0到ALT + NumPad9产生:

  

键是alt + System

Ctrl正常工作

键是ctrl + NumPad1
键是ctrl + NumPad2
键是ctrl + NumPad3

2 个答案:

答案 0 :(得分:1)

您可以使用SELECT Number, SUM(TIME_TO_SEC(TIMEDIFF(DateEnd, DateBgn))) AS Duration FROM calls WHERE UserId = 10 AND Type = 1 # Incomming Call GROUP BY Number ORDER BY 2 DESC LIMIT 10; Keyboard.Modifiers属性通过KeyEventArgs.SystemKey检测ALT+1

ALT+9
private void MainWindow_PreviewKeyDown(object sender, KeyEventArgs e)
{
    if (Keyboard.Modifiers == ModifierKeys.Alt)
    {
        string ctrlMod = "alt + " + e.SystemKey.ToString();
        Debug.WriteLine("Key is " + ctrlMod);
    }
}   

答案 1 :(得分:0)

我认为maccettura是正确的,它与'Windows Alt代码'有关。我可以使用

绕过它
if (Keyboard.IsKeyDown(Key.NumPad0)) { }