Q: Keydown event not working!

  • Thread starter Thread starter MarkD
  • Start date Start date
M

MarkD

Hey,

I'm using Access 2000 and trying to get the keydown thing
to work, but it's not.

This is the code behind the event:
'===========
Private Sub DBA_NAME_KeyDown(KeyCode As Integer, Shift As
Integer)
If KeyCode = Asc(",") Then
KeyCode = 0
End If
Debug.Print Chr(KeyCode), KeyCode, Shift
End Sub
'===========

This is what shows up on the debug window when I type
"markd,"

M 77 0
A 65 0
R 82 0
K 75 0
D 68 0
¼ <=== 188 <=== 0

What's with the 188 value when I type a comma? It seems
only the non alphanumeric characters are returning weird
keycodes (1,2,3... a,b,c... work as expected)
 
MarkD said:
Hey,

I'm using Access 2000 and trying to get the keydown thing
to work, but it's not.

This is the code behind the event:
'===========
Private Sub DBA_NAME_KeyDown(KeyCode As Integer, Shift As
Integer)
If KeyCode = Asc(",") Then
KeyCode = 0
End If
Debug.Print Chr(KeyCode), KeyCode, Shift
End Sub
'===========

This is what shows up on the debug window when I type
"markd,"

M 77 0
A 65 0
R 82 0
K 75 0
D 68 0
¼ <=== 188 <=== 0

What's with the 188 value when I type a comma? It seems
only the non alphanumeric characters are returning weird
keycodes (1,2,3... a,b,c... work as expected)

The KeyCode passed to the KeyDown event procedure is *not* (necessarily)
the ASCII value that corresponds to the key that was pressed. It more
closely corresponds to the keyboard scan code of the key that is
pressed, though I'm not sure that is does so in all cases. The KeyDown
event fires even for non-ASCII keys, so the KeyCode cannot be defined as
the ASCII value of the key. The fact that it does for the common
alphanumeric keys is, I believe, historical happenstance.

There is a set of constants defined for the keycodes returned in the
KeyDown event -- vbKey1, vbKeyA, vbKeyRight, etc. -- but I don't see one
for the "comma/less-than" key. If that key's code happens to be 188,
that's just the way it is.

If you are interested only in the ASCII keys, use the KeyPress event
instead.
 
-----Original Message-----


The KeyCode passed to the KeyDown event procedure is *not* (necessarily)
the ASCII value that corresponds to the key that was pressed. It more
closely corresponds to the keyboard scan code of the key that is
pressed, though I'm not sure that is does so in all cases. The KeyDown
event fires even for non-ASCII keys, so the KeyCode cannot be defined as
the ASCII value of the key. The fact that it does for the common
alphanumeric keys is, I believe, historical happenstance.

There is a set of constants defined for the keycodes returned in the
KeyDown event -- vbKey1, vbKeyA, vbKeyRight, etc. -- but I don't see one
for the "comma/less-than" key. If that key's code happens to be 188,
that's just the way it is.

If you are interested only in the ASCII keys, use the KeyPress event
instead.

--
Dirk Goldgar, MS Access MVP
www.datagnostics.com

(please reply to the newsgroup)


.
 
Back
Top