How to get a code of pressed key ?
-
-
try this this is a small key pressed event private void cbfilmoname_KeyPress(object sender, System.Windows.Forms.KeyPressEventArgs e) { if(e.KeyChar==0xd) { mymethod(); } } // "0xd" means that the Key Pressed is "ENTER" key // you can find the KeyChar of the any key with tracing this code // or in help documents
-
Hi, there are 3 keyboard events: KeyDown, KeyPress, KeyUp the documentation states: The KeyPress event is not raised by noncharacter keys; however, the noncharacter keys do raise the KeyDown and KeyUp events. noncharacter keys include shift, alt, control, shift lock, ... KeyDown and KeyUp offer KeyCode, KeyChar and KeyValue properties; KeyPress only offers KeyChar. The rationale seems to be special characters can be recognized during KeyDown/Up, whereas KeyPress only is fired for normal characters, where KeyCode would not be relevant. But the KeyPressEventArgs does offer information on the state of the modifier keys (Control, Alt, Shift). Note: normal characters have autorepeat, the special ones dont. Warning: the KeyPress event fires when the key gets released (or the autorepeat delay is reached). The KeyDown event fires immediately when the key goes down. Conclusion: if you really need KeyCode, use KeyDown event. :)
Luc Pattyn [My Articles]
-
Hi, there are 3 keyboard events: KeyDown, KeyPress, KeyUp the documentation states: The KeyPress event is not raised by noncharacter keys; however, the noncharacter keys do raise the KeyDown and KeyUp events. noncharacter keys include shift, alt, control, shift lock, ... KeyDown and KeyUp offer KeyCode, KeyChar and KeyValue properties; KeyPress only offers KeyChar. The rationale seems to be special characters can be recognized during KeyDown/Up, whereas KeyPress only is fired for normal characters, where KeyCode would not be relevant. But the KeyPressEventArgs does offer information on the state of the modifier keys (Control, Alt, Shift). Note: normal characters have autorepeat, the special ones dont. Warning: the KeyPress event fires when the key gets released (or the autorepeat delay is reached). The KeyDown event fires immediately when the key goes down. Conclusion: if you really need KeyCode, use KeyDown event. :)
Luc Pattyn [My Articles]