Detect when two keys are pressed at the same time

后端 未结 4 1166
北海茫月
北海茫月 2020-12-10 07:18

I have no idea how do this.

I know only how do detect one key:

private void Form1_KeyDown(object sender, KeyEventArgs e)
{
    if (e.KeyCode == Keys         


        
4条回答
  •  暗喜
    暗喜 (楼主)
    2020-12-10 08:12

    put a break point in your key down event and press your two keys together.
    examine the KeyData of the KeyEventArgs. it will show you what you have to use to detect two keys pressed together. Use some dummy code like this:

    private void Form1_KeyDown(object sender, KeyEventArgs e)
    {
        MessageBox.Show("KeyData is: " + e.KeyData.Tostring());
    }
    

    like I have done for shift and r pressed together

    e.KeyData = R | Shift

提交回复
热议问题