Sendkeys

accessman2

Registered User.
Local time
Today, 09:31
Joined
Sep 15, 2005
Messages
335
Hi,

I want to do Sendkeys "{NUMLOCK}" when the form is Active. But, the sendkeys statement doesn't work. I want to use the VB code to turn on the NUMLOCK. And, I want to check whether or not the NUMLOCK is on/off, how can I check it?
 
I would assume to do this you will need to make some API calls to retrieve the state of the button. I have a good refrence at I can look at when I get off of work. I will post back if I find the API calls.
 
You don't mention which version of Access you're using, but there's a pretty well-known bug with some versions (2000 and 97 at least, if I recall correctly) where using the Sendkeys command actually messes up the NUM LOCK key - turns it off. So if you're already using SendKeys elsewhere in your Access database, that could be causing the problem that you're trying to solve here.

Here's a Microsoft article that explains how to toggle the NUM LOCK key:
http://support.microsoft.com/kb/177674
 
As KeithG said, you'll need an API call. In a standard module place this code:

Code:
'*********************************************
'Windows API/Global Declarations for :NumLock
'*********************************************

'Public Const VK_CAPLOCK = &H14
Public Const VK_NUMLOCK = &H90

Public Type KeyboardBytes
kbByte(0 To 255) As Byte
End Type
Public kbArray As KeyboardBytes
    
Public Declare Function GetKeyState Lib "user32" _
(ByVal nVirtKey As Long) As Long
Public Declare Function GetKeyboardState Lib "user32" _
(kbArray As KeyboardBytes) As Long
Public Declare Function SetKeyboardState Lib "user32" _
(kbArray As KeyboardBytes) As Long
Code:
'********************************************
'Add the following code to the form
'********************************************
Private Function NumLock() As Integer
        NumLock = GetKeyState(VK_NUMLOCK) And 1 = 1
End Function

Private Sub Form_Current()
   GetKeyboardState kbArray
   kbArray.kbByte(VK_NUMLOCK) = 1
   SetKeyboardState kbArray
End Sub
As far as determing the state, here's a way to do it with a command button and messageboxes. The code can, of course, be adapted:

Code:
Private Sub NLState_Click()
  If vbKeyNumlock = True Then
     MsgBox ("NM On")
  Else
     MsgBox ("NM Off")
End If
End Sub
 

Users who are viewing this thread

Back
Top Bottom