C# getting keyboard inputs
-
How do I get keyboard inputs like 'X' to exit and maybe right arrow to go to next frame, etc. I tried protected override void OnKeyDown(KeyEventArgs e) { if(e.KeyCode == Keys.X); Close(); } ut I am not sure about the event handler I need to put out Thanks! Samuel
-
How do I get keyboard inputs like 'X' to exit and maybe right arrow to go to next frame, etc. I tried protected override void OnKeyDown(KeyEventArgs e) { if(e.KeyCode == Keys.X); Close(); } ut I am not sure about the event handler I need to put out Thanks! Samuel
Hi! What's wrong with the code? What do you mean by "putting out" an event handler? Your implementation of
OnKeyDown
is a way to handle theKeyDown
event...Regards, mav -- Black holes are the places where God divided by 0...
-
How do I get keyboard inputs like 'X' to exit and maybe right arrow to go to next frame, etc. I tried protected override void OnKeyDown(KeyEventArgs e) { if(e.KeyCode == Keys.X); Close(); } ut I am not sure about the event handler I need to put out Thanks! Samuel
Like the below Convert.ToInt32 (e.KeyChar ) == 95 // this is for 'a' you can find constant integer valus of X and validate against it then proceed.
-
How do I get keyboard inputs like 'X' to exit and maybe right arrow to go to next frame, etc. I tried protected override void OnKeyDown(KeyEventArgs e) { if(e.KeyCode == Keys.X); Close(); } ut I am not sure about the event handler I need to put out Thanks! Samuel
Hi, there are several Keyboard events: - KeyDown and KeyUp events provide e.KeyCode (type Keys) and e.KeyValue (the int value of KeyCode); it also fires when pressing/releasing modifier keys (CTRL, ALT, SHIFT, ...) - for printable keys (the ones that normally add text in a text editor) you better use KeyPress event which provides e.KeyChar (char), so you dont need to refer to the Keys enumeration nor the explicit conversion to integers. :)
Luc Pattyn
try { [Search CP Articles] [Search CP Forums] [Forum Guidelines] [My Articles] } catch { [Google] }