2

I'm trying to get the key pressed on the keyboard (not a specific), i watched somes "solutions" everywhere and i found nothing working. Conditions: Need anchoring a panel on the form.

HHopter
  • 23
  • 6

2 Answers2

1

Try this in your Form1.cs

protected override bool ProcessCmdKey(ref Message msg, Keys keyData)
{
    if (keyData == Keys.T)
    {
        MessageBox.Show("THIS IS T");
    }

    return base.ProcessCmdKey(ref msg, keyData);
}
Josef
  • 2,869
  • 2
  • 22
  • 23
KangKang
  • 11
  • 1
1

As I understood, you put the focus on a button B and defined that if the A key is pressed, the code related to the A button will be executed.

Use code:

protected override bool ProcessCmdKey(ref Message message, Keys KeyData)
{
    switch (KeyData)
    {
        case Keys. A:
            MessageBox.Show("Hello");
            break;
    }
    return true;
}