1
I’m trying to capture the value of each key in C# by the Keydown event, works perfectly, but the value of each is returned by numbers, for example when pressing TAB is captured 9.
There would be a way to get the value of the key by name, without using multiple ifs?
private void Form1_KeyDown(object sender, KeyEventArgs e)
{
string teclaDigitada = Convert.ToString(e.KeyValue);
label1.Text = teclaDigitada;
if (teclaDigitada == "38") { label2.Text = "SETA-CIMA"; }
if (teclaDigitada == "40") { label2.Text = "SETA-BAIXO"; }
if (teclaDigitada == "37") { label2.Text = "SETA-ESQUERDA"; }
if (teclaDigitada == "39") { label2.Text = "SETA-DIREITA"; }
if (teclaDigitada == "9") { label2.Text = "TAB"; }
if (teclaDigitada == "20") { label2.Text = "CAPS LOOK"; }
if (teclaDigitada == "16") { label2.Text = "SHIFT"; }
if (teclaDigitada == "17") { label2.Text = "CTRL"; }
if (teclaDigitada == "91") { label2.Text = "WINDOWS"; }
if (teclaDigitada == "18") { label2.Text = "ALT"; }
}