I have a .NET app with buttons which use numbers for mnemonics. (e.g. "&1 - Check" and "&2 - Cash") When I hit Alt+1, I expect the Check button to be clicked. This works when I use the standard number keys on a keyboard. However, when I hit Alt+1 using the number pad, Windows takes over and inserts the symbol that matches the "alt code" of 1. See http://alt-codes.org/list/. How can I prevent this from happening in my application?
Thanks!
This can be done by enabling KeyPreview on the form and handling the KeyUp event. The following code bypasses the Windows alt codes functionality and causes the button to click when I hit Alt+NumPad1:
if (e.Alt && e.KeyCode == Keys.NumPad1)
{
e.Handled = true;
button1.PerformClick();
}
This Alt+numkey combination is a Windows feature (very useful), you cannot bypass it.
I have tried this a while ago while working on a game (you know... skills bar shortcuts? ☺) and I have done some research... It is impossible.
I'd be very happy to see a way over this, too!
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With