How to capture a key pressed in C #

0

I have an application with digit buttons and I want to capture the keystrokes and execute the events of those buttons. I added an event of keypress in the window and tried to capture the key typed, but I could not.

Code:

private void CalculadoraDS2_KeyPress(object sender, KeyPressEventArgs e)
{
    if(e.KeyChar.GetType == '0')
    {
        btn0.PerformClick();
    }
}
    
asked by anonymous 01.03.2018 / 18:53

1 answer

2

Follow the code below:

if (e.KeyChar == (char)Keys.D0)
{
    //tecla 0 pressionada
    btn0.PerformClick();
    e.Handled = true;
}

For more information: here .

Complete list of all the key codes Keys Enum : here .

    
01.03.2018 / 19:11