Question re KeyPress

S

Sophie

Merry Christmas to all

I have 2 questions involving the KeyPress event:

1) I use a numeric keypad that plugs into my laptop's USB port. I have
programmed the '*' and '/' keys on the keypad to go to the Next or Prev
record in my subform:

Private Sub Form_KeyPress(KeyAscii As Integer)
If KeyAscii = 42 Then
KeyAscii = 0
RunCommand acCmdSaveRecord
Forms!frmEnterScores.cmdNext.SetFocus
Call cmdNext_Click
.... etc

Is there any way to restrict the code to the '*' and '/' on the keypad
alone, not the ones on the regular keyboard.

2) How can I do the same thing ( Call cmdNext_Click or Call cmdPrev_Click
using the Right Arrow and the Left Arrow on the main keyboard? I can't seem
to find Ascii codes for these buttons.

much thanks
Thanks
Sophie
 
S

Stuart McCall

Sophie said:
Merry Christmas to all

I have 2 questions involving the KeyPress event:

1) I use a numeric keypad that plugs into my laptop's USB port. I have
programmed the '*' and '/' keys on the keypad to go to the Next or Prev
record in my subform:

Private Sub Form_KeyPress(KeyAscii As Integer)
If KeyAscii = 42 Then
KeyAscii = 0
RunCommand acCmdSaveRecord
Forms!frmEnterScores.cmdNext.SetFocus
Call cmdNext_Click
.... etc

Is there any way to restrict the code to the '*' and '/' on the keypad
alone, not the ones on the regular keyboard.

2) How can I do the same thing ( Call cmdNext_Click or Call cmdPrev_Click
using the Right Arrow and the Left Arrow on the main keyboard? I can't
seem
to find Ascii codes for these buttons.

much thanks
Thanks
Sophie

To answer both questions: you need to use the KeyDown or KeyUp events to
trap the keycode. Keycode is not the same thing as KeyAscii, which is what
is passed to the KeyPress procedure. It is a keyboard scan code, which is
the raw code that the computer receives from the keyboard electronics.

Using the KeyDown event, the equivalent of KeyAscii = 0 is KeyCode = 0, but
other than that you can code the event the same way. All you need now are
some keycode constants:

* = vbKeyMultiply
/ = vbKeyDivide
Left Arrow = vbKeyLeft
Right Arrow = vbKeyRight

You can find a list of constants in help. Search for 'keycode constants'.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top