|
-
Sep 24th, 2001, 02:53 AM
#1
Thread Starter
Frenzied Member
Can you turn on NumLock from VB ?
Another week, another barrage of questions................
If a user starts to type using the NumLock key, is it possible to detect this and turn NumLock on ?
Alternatively, is it easy enough to have a program turn NumLock on when it starts up ?
Thanks.
-
Sep 24th, 2001, 03:05 AM
#2
New Member
please don't ask me how
i do know it's possible --- so the answer to your question is yes... i know this because i have seen a "certain" program written in vb that does just what you want
at least now you know the answer
i just can't tell you how
MAYBE I GAVE YOU HOPE!!!!!!!!!
-
Sep 24th, 2001, 04:52 AM
#3
-
Sep 24th, 2001, 06:23 AM
#4
Private Declare Function GetKeyboardState Lib "user32" (pbKeyState As Byte) As Long
Private Declare Function SetKeyboardState Lib "user32" (lppbKeyState As Byte) As Long
Private Const VK_CAPITAL = &H14
Private Const VK_NUMLOCK = &H90
Private Const VK_SCROLL = &H91
ReDim KeyboardBuffer(256) As Byte
GetKeyboardState KeyboardBuffer(0)
'This example show you how to press the Caps Lock button. if you want
'to press the Num Lock button, Replace all the following 3 'VK_CAPITAL'
'with 'VK_NUMLOCK' or VK_SCROLL as desired.
If KeyboardBuffer(VK_CAPITAL) And 1 Then
KeyboardBuffer(VK_CAPITAL) = 0
Else
KeyboardBuffer(VK_CAPITAL) = 1
End If
SetKeyboardState KeyboardBuffer(0)
-
Sep 24th, 2001, 08:53 PM
#5
Junior Member
I could not get the API calls:
GetKeyboardState
and
SetKeyboardState
to work. However, the following code seems to work a treat.
' Declare the API function and associated constant
Private Declare Sub keybd_event Lib "user32" (ByVal bVk As Byte, ByVal bScan As Byte, ByVal dwFlags As Long, ByVal dwExtraInfo As Long)
Private Declare Function GetKeyState Lib "user32" (ByVal nVirtKey As Long) As Integer
Private Const VK_NUMLOCK = &H90 Private Const KEYEVENTF_EXTENDEDKEY = &H1 Private Const KEYEVENTF_KEYUP = &H2
' Now use the follwing code:
If GetKeyState(VK_NUMLOCK) Then
Else
keybd_event VK_NUMLOCK, 0, 0, 0
End If
-
Feb 3rd, 2011, 09:03 AM
#6
New Member
Re: Can you turn on NumLock from VB ?
This does not work correctly as it sends a Key Down code but not a keyup code. So if the user presses the Num Lock key it does not work the first time. This code works better (as expected)
keybd_event VK_NUMLOCK, 0, 0, 0 'send NumLock keydown
keybd_event VK_NUMLOCK, 0, KEYEVENTF_KEYUP, 0 'send numlock keyup
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|