Good day, friends! I am writing a program in which you can set hotkeys for actions. And ran into a problem in the numeric keypad. If you click for example 0
(on the numeric keypad ), then in the textbox
in the KeyDown
, e.KeyCode
will be Keys.NumPad0
, and if you press SHIFT + 0
(on the numeric keypad ), then e.KeyCode = Keys.Insert
, and e.Modifiers = Keys.None
and e.Shift = false;
private void textBox1_KeyDown(object sender, KeyEventArgs e) { if (e.Shift && e.KeyCode == Keys.NumPad0) { MessageBox.Show("SHIFT + NumPad0"); } }
Through experiments, I found out that when the OS is pressed, the OS and NumPad0
convert it to Insert
, and to be exact, it programmatically “squeezes out” Shift
and replaces this combination with Insert
. Therefore, a condition is added to the KeyDown
method.
if (e.Modifiers == Keys.Shift) { _FlagShiftPressed = true; }
and in the keyup method
if (e.Shift == false & e.Modifiers == Keys.Shift) { _FlagShiftPressed = false; }
Thus, it turned out to handle any clicks on the numeric keypad with any modifier. But after that the underwater rock came out. When you click on SHIFT
, release and then click on Insert
(for example), we get the result as if you press SHIFT+0
(on the digital keyboard). Those. in the KeyUp
event, when the Shift
released, the flag is not reset and the processing proceeds as if the numeric keypad is pressed. If it was not clear expressed, then you can look at the example of setting the "hot buttons" in the properties of the shortcut. How can I get around this problem, or can there be other more rational solutions?