Capturing F5 Keypress
-
Hi, I am trying to enable the keypress event for 'F5' key to refresh my form... Because I found that the normal KeyPress event does not work for function keys, I tried overriding the PreProcessMessage() function, as follows : public override bool PreProcessMessage(ref Message msg) { try { if (msg.Msg == WM_KEYDOWN) { Keys keyCode = (Keys)msg.WParam & Keys.KeyCode; if (keyCode == Keys.F5) { //code } } return PreProcessMessage(ref msg); } catch (Exception ex) { throw; } } But the control never gets into this method... Can anyone help me fix this? Thanks in advance, ramzg
-
Hi, I am trying to enable the keypress event for 'F5' key to refresh my form... Because I found that the normal KeyPress event does not work for function keys, I tried overriding the PreProcessMessage() function, as follows : public override bool PreProcessMessage(ref Message msg) { try { if (msg.Msg == WM_KEYDOWN) { Keys keyCode = (Keys)msg.WParam & Keys.KeyCode; if (keyCode == Keys.F5) { //code } } return PreProcessMessage(ref msg); } catch (Exception ex) { throw; } } But the control never gets into this method... Can anyone help me fix this? Thanks in advance, ramzg
-
Hi, I am trying to enable the keypress event for 'F5' key to refresh my form... Because I found that the normal KeyPress event does not work for function keys, I tried overriding the PreProcessMessage() function, as follows : public override bool PreProcessMessage(ref Message msg) { try { if (msg.Msg == WM_KEYDOWN) { Keys keyCode = (Keys)msg.WParam & Keys.KeyCode; if (keyCode == Keys.F5) { //code } } return PreProcessMessage(ref msg); } catch (Exception ex) { throw; } } But the control never gets into this method... Can anyone help me fix this? Thanks in advance, ramzg
You use the wrong syntax!, the correct syntax is
protected override bool ProcessCmdKey(
ref Message m,
Keys keyData
)Try this:
protected override bool ProcessCmdKey(ref Message msg, Keys keyData) { if (keyData == Keys.F5) { MessageBox.Show("F5 pressed!"); } return base.ProcessCmdKey(ref msg, keyData); }
Hope this help.
;)*12Code
-
You use the wrong syntax!, the correct syntax is
protected override bool ProcessCmdKey(
ref Message m,
Keys keyData
)Try this:
protected override bool ProcessCmdKey(ref Message msg, Keys keyData) { if (keyData == Keys.F5) { MessageBox.Show("F5 pressed!"); } return base.ProcessCmdKey(ref msg, keyData); }
Hope this help.
;)*12Code