I have a Windows.Form and there overriden ProcessCmdKey. However, this works with all of the F-Keys except for F10 . I am trying to search for the reason why ProcessCmdKey is not called when I press F10 on my Form.
Can someone please give me a tip as to how I can find the cause?
Best Regards, Thomas
Windows treats F10 differently. An explanation is given in the "Remarks" section here on MSDN
I just tested this code with Windows Forms on .NET 4 and I got the 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);
}
May be I got your problem, so trying to guess:
Did you set KeyPreview
property of your WindowsForm to true
?
This will enable possiblity to WindowsForm proceed keypress events before they pump to the control that holds the focus on UI in that precise moment.
Let me know if it works, please.
Regards.
In my case I was trying to match e.key to system.windows.input.key.F10 and it didn't not 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 it worked.
If running into this issue in a WPF app, this blog post shows how to capture 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:
}
}
Right, and as this is a special key you must add
e.Handled = true;
it tells the caller that you handled it.
So, your code could look like:
switch (e.Key)
...
case Key.System:
if (e.SystemKey == Key.F10)
{
e.Handled = true;
... processing
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.