PDA

Click to See Complete Forum and Search --> : trapping the arrow keys


Kramer
Nov 2nd, 1999, 12:54 AM
I need to know when an arrow key has been pressed but I can't locate the code to use for trapping them.

Frans C
Nov 2nd, 1999, 01:01 AM
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

MartinLiss
Nov 2nd, 1999, 01:09 AM
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