Search code examples
c#.netkey

Detect when two keys are pressed at the same time


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.C)
    {
        MessageBox.Show("C key");
    }
}

Solution

  • You have to keep track of keydown/keyup events, and keep a list of all the keys that are currently "down". The keyboard handler can only trigger on individual keys, and it's up to your code to detect/keep track of which ones are down, and if those individual keydown events are close enough to each other to be counted as "together".