C#: In the keydown event of a textbox, how do you detect currently pressed modifiers + keys?

前端 未结 2 1906
北海茫月
北海茫月 2021-01-06 15:55

C#: In the keydown event of a textbox, how do you detect currently pressed modifiers + keys?

I did the following, but I\'m not too familiar with these operators so I

2条回答
  •  情书的邮戳
    2021-01-06 16:19

    The documentation says it is a bitwise combination, but you're doing a logical OR.

    Try:

    if (e.Modifiers & (Keys.Alt | Keys.Control | Keys.Shift))
    {
        lbLogger.Items.Add(e.Modifiers.ToString() + " + " +
            "show non-modifier key being pressed here");
    }
    

    And I think you can get the actual key with e.KeyCode.ToString().

提交回复
热议问题