NumLock Key -- Keeping it On(?)

C

croy

On some data-entry forms, I'd like to neutralize accidental
hits to the NumLock key (that would turn it off).

I tried this:

Private Sub Form_KeyDown(KeyCode As Integer, Shift As
Integer)

If KeyCode = vbKeyNumlock Then
DoCmd.CancelEvent
Else
End If

End Sub

.... but it doesn't seem to work.

Any thoughts appreciated.
 
C

croy

Try:

If KeyCode = vbKeyNumlock Then
KeyCode = 0
End If

Thanks for the reply Jon, but I haven't been able to get
that to work. I've tried it in the KeyDown event for a
control, and in then in the KeyUp event, but no cigar.

As I think it thru a little further, I'm wondering if maybe
I'm fighting a hardware/firmware issue. The keyboard has an
indicator light for the toggle status of the NumLock key.
I've experimented, using the SendKeys command, and it does
not seem to affect the status of NumLock. Maybe there's
another layer of complexity with such keys...? I seem to
remember that the BIOS can be set for NumLock ON or OFF on
bootup, so there must be *some* way of controlling it... I
dunno!
 
C

croy

Thanks for the reply Jon, but I haven't been able to get
that to work. I've tried it in the KeyDown event for a
control, and in then in the KeyUp event, but no cigar.

As I think it thru a little further, I'm wondering if maybe
I'm fighting a hardware/firmware issue. The keyboard has an
indicator light for the toggle status of the NumLock key.
I've experimented, using the SendKeys command, and it does
not seem to affect the status of NumLock. Maybe there's
another layer of complexity with such keys...? I seem to
remember that the BIOS can be set for NumLock ON or OFF on
bootup, so there must be *some* way of controlling it... I
dunno!

The "If..." part of that *is* working. If I understand
correctly, the "KeyCode = 0" part is intended to effectively
cancel the keystroke, but that doesn't seem to happen in
this case.

If there is Access VB code for determining the status of the
NumLock key, that might be something to experiment with...
 
J

Jon Lewis

You're right, it seems that NumLock can't be captured this way.

A quick google suggests it's pretty difficult to programmatically control
this key. You could try some Windows API functions if you are familiar with
APIs.

Jon
 

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