[AccessD] Num Lock

Drew Wutka DWUTKA at marlow.com
Wed Dec 10 11:57:42 CST 2003


No clue where my original function is.....haven't used it in years.
However, here's something that does just as well.  Create a Class Module and
paste this code into it:

Option Compare Database
Option Explicit
Private Type OSVERSIONINFO
  dwOSVersionInfoSize As Long
  dwMajorVersion As Long
  dwMinorVersion As Long
  dwBuildNumber As Long
  dwPlatformId As Long
  szCSDVersion As String * 128
End Type
Private Declare Function GetVersionEx Lib "kernel32" _
   Alias "GetVersionExA" _
   (lpVersionInformation As OSVERSIONINFO) As Long
Private Declare Sub keybd_event Lib "user32" _
   (ByVal bVk As Byte, _
    ByVal bScan As Byte, _
    ByVal dwFlags As Long, ByVal dwExtraInfo As Long)
Const VK_NUMLOCK = &H90
Const KEYEVENTF_EXTENDEDKEY = &H1
Const KEYEVENTF_KEYUP = &H2
Const VER_PLATFORM_WIN32_NT = 2
Const VER_PLATFORM_WIN32_WINDOWS = 1
Private Declare Function GetKeyState Lib "user32" (ByVal lngVirtKey As Long)
As Integer
Private Declare Function GetKeyboardState Lib "user32" (bytKeyState As Byte)
As Long
Private Declare Function SetKeyboardState Lib "user32" (bytKeyState As Byte)
As Long
Property Get Numlock() As Boolean
Numlock = CBool(GetKeyState(vbKeyNumlock) And 1)
End Property
Property Let Numlock(Value As Boolean)
Call SetKeyState(Value)
End Property
Private Sub SetKeyState(fTurnOn As Boolean)
Dim abytBuffer(0 To 255) As Byte
Dim o As OSVERSIONINFO
o.dwOSVersionInfoSize = Len(o)
GetVersionEx o
If o.dwPlatformId = VER_PLATFORM_WIN32_WINDOWS Then
  Call GetKeyboardState(abytBuffer(0))
  abytBuffer(VK_NUMLOCK) = CByte(Abs(fTurnOn))
  Call SetKeyboardState(abytBuffer(0))
Else
  keybd_event VK_NUMLOCK, &H45, KEYEVENTF_EXTENDEDKEY Or 0, 0
  keybd_event VK_NUMLOCK, &H45, KEYEVENTF_EXTENDEDKEY Or KEYEVENTF_KEYUP, 0
End If
End Sub


Then save that class module and call it Keyboard.

To test the code, put a toggle button on a form, and call it tglNumlock.
Then put this code behind the form:

Private Sub Form_Load()
Dim kb As Keyboard
Set kb = New Keyboard
Me.tglNumLock.Value = kb.Numlock
Set kb = Nothing
End Sub
Private Sub tglNumLock_Click()
Dim kb As Keyboard
Set kb = New Keyboard
kb.Numlock = Me.tglNumLock.Value
Set kb = Nothing
End Sub

I actually downloaded the original Keyboard class a while back.  I think Ken
Getz wrote it.  But the Numlock function didn't work in NT, so I had to
modify it.  The original class had all sorts of other properties, which I
never used...so I just stripped it down to just Numlock for this post.

Drew
-----Original Message-----
From: Christian, Lorraine [mailto:LChristian at massmutual.com]
Sent: Wednesday, December 10, 2003 6:29 AM
To: Access Developers discussion and problem solving
Subject: RE: [AccessD] Num Lock


Hi there!

Drew, do you care to share your function?  :)

Thanks.

Lorraine




More information about the AccessD mailing list