I need to know when an arrow key has been pressed but I can't locate the code to use for trapping them.
Printable View
I need to know when an arrow key has been pressed but I can't locate the code to use for trapping them.
If you want to know if an arrow key is pressed for one control, you can use the KeyDown event of the specific control. If you want to know this for the complete form, set the KeyPreview Property of the form to True and use the form's KeyDown event. The KeyCode paramter tells you which key has been pressed.
Left arrow : KeyCode = 37
Up arrow : KeyCode = 38
Right arrow : KeyCode = 39
Down arrow : KeyCode = 40
Rather than use hard-coded "magic numbers" like 37, 38, etc., use the built-in vbKey... constants instead. For example vbKeyLeft has a value of 37.
------------------
Marty