Link to home
Start Free TrialLog in
Avatar of st
st

asked on

Small script to enable the Num Lock key

How to use a small QB/VB script to enable the Num Lock key?
(Preferer use QB command if you know.)

Thanks.
ASKER CERTIFIED SOLUTION
Avatar of Dr. Kamal Mehdi
Dr. Kamal Mehdi
Flag of Greece image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Here is some other code for manipulating the CapsLock, NumLock, etc. without using the KeyState control (in VB):

Functin GetCapslock() As Boolean
'     ' Return or set the Capslock toggle.
GetCapslock = CBool(GetKeyState(vbKeyCapital) And 1)
End Function

Fuction GetNumlock() As Boolean
'     ' Return or set the Numlock toggle.
GetNumlock = CBool(GetKeyState(vbKeyNumlock) And 1)
End Function


Function GetScrollLock() As Boolean

       '     ' Return or set the ScrollLock toggle.
       GetScrollLock = CBool(GetKeyState(vbKeyScrollLock) And 1)
End Function


Sub SetCapslock(Value As Boolean)

       '     ' Return or set the Capslock toggle.
       Call SetKeyState(vbKeyCapital, Value)
End Sub


Sub SetNumlock(Value As Boolean)

       '     ' Return or set the Numlock toggle.
       Call SetKeyState(vbKeyNumlock, Value)
End Sub

Set SetScrollLock(Value As Boolean)
'     ' Return or set the ScrollLock toggle.
Call SetKeyState(vbKeyScrollLock, Value)
End Sub


Private Sub SetKeyState(intKey As Integer, fTurnOn As Boolean)

       '     ' Retrieve the keyboard state, set the particular
       '     ' key in which you're interested, and then set
       '     ' the entire keyboard state back the way it
       '     ' was, with the one key altered.
       Dim abytBuffer(0 To 255) As Byte
       GetKeyboardState abytBuffer(0)
       abytBuffer(intKey) = CByte(Abs(fTurnOn))
       SetKeyboardState abytBuffer(0)
End Sub