KeyDown/KeyCode & KeyPress/KeyAscii

  • Thread starter Thread starter RxB
  • Start date Start date
R

RxB

If I use KeyPress the KeyAscii parameter returned for the"#" key is 35.
If I use KeyDown the KeyCode parameter returned for the"#" key is 222.

The 35 I understand and is documented in the VB help. However the 222 is a
mystery to me. The help for KeyDown is a little vauge in this area. Is there
a
list somewhere that documents what is returned to the KeyCode of the
KeyDown event.

Many thanks,
Roy
 
Check Access VB Help Topic "KeyCode Constants".

Roughly, I tend to think KeyCode is the code associated with each key on
your keyboard (i.e. the code sent by the keyboard to the OS / Access) and
Access uses the states of the Shift / Ctrl / Alt Key to determine what to do
with the KeyCode, i.e. whether to interpret it as Input Data or a Command to
do something. If it is a piece of Input Data, it is translate to a
KeyAscii. For A-Z and 0-9 (and some others), the KeyCode and KeyAscii are
the same.

Think of it this way: If you press the key "A" on your keyboard (there is
only 1 Keycode) but depending on the Shift key, this can be interpreted as
"A" or "a", i.e. 2 different ASCII codes possible.
 
Van,
Many thanks for your help. I have been through the help and can't find any
reference to # being 222. The KeyCode character set indicates a value of
35 for #. I just don't understand the 222....

The problem I have at the moment is that I have some text boxes that accept
numerical data. I also detect a a number special keys (=, # and t) and take
some special action. I use KeyPress to do this. I now want to add some extra
functionality to this so I would like to detect the same keys but with the
Cntrl
or Alt key also pressed. Hence I was considering moving away from KeyPress
to KeyDown / Up.

I suppose I can use the 222 that I've found empiricaly but I don't feel
comfortable
doing that! Will it work on all keyboards? I'm using an old IBM keyboard -
(probably
not a lot of consistency with any open standards there :-) And then there ar
probably
problems associated with UK/US keyboards... (I'm in the UK)

Hmmm....

Many thanks,
Roy
 
I am using the laptop so my # is actually Shift + 3. The Keycode for Shift
is 16 and Keycode for 3 is 51. The KeyAscii for Shift + 3 is 35 (#). I can
find KeyCode 222 on my keyboard but your keyboard obviously has more keys
which is recognise correct and being converted to KeyAscii correctly.
 
Back
Top