C# getting keyboard inputs
-
How do I get keyboard inputs like 'X' to exit and maybe right arrow to go to next frame, etc. I tried protected override void OnKeyDown(KeyEventArgs e) { if(e.KeyCode == Keys.X); Close(); } ut I am not sure about the event handler I need to put out Thanks! Samuel
-
How do I get keyboard inputs like 'X' to exit and maybe right arrow to go to next frame, etc. I tried protected override void OnKeyDown(KeyEventArgs e) { if(e.KeyCode == Keys.X); Close(); } ut I am not sure about the event handler I need to put out Thanks! Samuel
Hello, On your MainForm you have to set the "KeyPreview" property and handle KeyPress.
//constructor code this.KeyPreview = true;
}
protected override void OnKeyPress(KeyPressEventArgs e)
{
if(e.KeyChar.Equals('X')||e.KeyChar.Equals('x'))
Close();
else
base.OnKeyPress (e);
}Hope it helps!
All the best, Martin
-
Hello, On your MainForm you have to set the "KeyPreview" property and handle KeyPress.
//constructor code this.KeyPreview = true;
}
protected override void OnKeyPress(KeyPressEventArgs e)
{
if(e.KeyChar.Equals('X')||e.KeyChar.Equals('x'))
Close();
else
base.OnKeyPress (e);
}Hope it helps!
All the best, Martin
Yes It Worked, exactly what I was looking for. Thanks Martin!
-
Yes It Worked, exactly what I was looking for. Thanks Martin!