GatorV Posted November 1, 2004 Share Posted November 1, 2004 How can I capture the arrow keys with my form, I can capture all of the keys except the arrow keys, does any one know how? :unsure: I have tried and only can capture them pressing Ctrl + the arrow, but the arrow alone can be captured by my form :angry: Hope anyone can help me :D Link to comment Share on other sites More sharing options...
0 Winston Posted November 1, 2004 Share Posted November 1, 2004 Private Sub Form1_KeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles MyBase.KeyDown If e.KeyCode = Keys.Up Then MessageBox.show("Up Arrow Pressed") End If End Sub Link to comment Share on other sites More sharing options...
0 GatorV Posted November 1, 2004 Author Share Posted November 1, 2004 Thanks, but I have tried that already It captures all of the keys I need except the arrow keys, I don't know maybe some property of the form, here is my code: Private Sub ControlForm_KeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles MyBase.KeyDown MessageBox.Show("KeyCode:" & e.KeyCode & " KeyData: " & e.KeyData & " KeyValue " & e.KeyValue & " Modifiers " & e.Modifiers) End Sub Link to comment Share on other sites More sharing options...
0 lexecutil Posted November 1, 2004 Share Posted November 1, 2004 You have to override ProcessCmdKey.. Heres an exmaple in C# :) protected override bool ProcessCmdKey(ref Message msg, Keys keyData) { if (keyData == Keys.Up) { ?MessageBox.Show("UP!"); ?return true; } return base.ProcessCmdKey (ref msg, keyData); } Dan Link to comment Share on other sites More sharing options...
0 GatorV Posted November 1, 2004 Author Share Posted November 1, 2004 Thanks Dan!! this is what I get.. Protected Overloads Overrides Function ProcessCmdKey(ByRef msg As Windows.Forms.Message, ByVal keydata As Windows.Forms.Keys) As Boolean If keydata = Keys.Up Then MessageBox.Show("Up Key") Return True End If Return MyBase.ProcessCmdKey(msg, keydata) End Function Thankyou verymuch :yes: :cool: Link to comment Share on other sites More sharing options...
0 lexecutil Posted November 1, 2004 Share Posted November 1, 2004 ALso a note about this.. it will catch keys being pressed in any child controls (unless they use the keys themselves)... This probably wont be a problem but just letting ya know :) Dan Link to comment Share on other sites More sharing options...
0 GatorV Posted November 1, 2004 Author Share Posted November 1, 2004 No, not a problem :D, I have completed my project, thanks! Link to comment Share on other sites More sharing options...
Question
GatorV
How can I capture the arrow keys with my form, I can capture all of the keys except the arrow keys, does any one know how? :unsure:
I have tried and only can capture them pressing Ctrl + the arrow, but the arrow alone can be captured by my form :angry:
Hope anyone can help me :D
Link to comment
Share on other sites
6 answers to this question
Recommended Posts