Key F10 not caught

I have Windows.Form and it overrides ProcessCmdKey. However, this works with all F keys except F10 . I am trying to find the reason why ProcessCmdKey is not being called when I press F10 in my form.

Can someone please give me a hint on how I can find the reason?

Best regards, Thomas

+7
source share
6 answers

Windows handles F10 differently. For an explanation, see the "Notes" section here on MSDN.

+8
source

I just tested this code with Windows Forms on .NET 4, and I got a message box as expected.

protected override bool ProcessCmdKey(ref Message msg, Keys keyData) { if (keyData == Keys.F10) { MessageBox.Show("F10 Pressed"); return true; } return base.ProcessCmdKey(ref msg, keyData); } 
+1
source

Maybe I have your problem, so I'm trying to guess:

Have you set the KeyPreview property of your WindowsForm to true ?

This will allow you to use WindowsForm to trigger keystroke events before they start pumping up the control that is currently focusing on the user interface.

Let me know if this works, please.

Sincerely.

+1
source

In my case, I tried to match e.key with system.windows.input.key.F10, and that didn't work (althougth F1 thru F9 did)

 Select Case e.Key Case is = Key.F10 ... do some stuff end select 

however I changed it to

 Select Case e.Key Case is = 156 ... do some stuff end select 

and he worked.

0
source

If you encounter this problem in a WPF application, this blog will show how to get the F10 key:

 private void Window_KeyDown(object sender, KeyEventArgs e) { if (e.SystemKey == Key.F10) { YourLogic(e.SystemKey); } switch (e.Key) { case Key.F1: case Key.F2: } } 
0
source

That's right, and since this is a special key, you must add

 e.Handled = true; 

this tells the caller that you have dealt with it.

So your code might look like this:

 switch (e.Key) ... case Key.System: if (e.SystemKey == Key.F10) { e.Handled = true; ... processing } 
0
source

Source: https://habr.com/ru/post/892570/


All Articles