|
-
Apr 22nd, 2002, 10:33 PM
#1
Thread Starter
Member
Problem w/ Capslock state for NT
Problem w/ Capslock state for NT
When using the following code, I do not always get the correct state of the Capslock key w/Windows NT.
Private Declare Function GetKeyboardState Lib "user32" _
(pbKeyState As Byte) As Long
Dim KeyState As Boolean
Dim keys(0 To 255) As Byte
GetKeyboardState keys(0)
KeyState = keys(VK_Type)
I'm trying to always turn off the capslock before using the keybd event and I need to check the status before toggling it.
Does anyone have a suggestion?
-
Apr 23rd, 2002, 02:24 AM
#2
From MSDN:
If the high-order bit is 1, the key is down; otherwise, it is up. If the low-order bit is 1, the key is toggled. A key, such as the CAPS LOCK key, is toggled if it is turned on. The key is off and untoggled if the low-order bit is 0. A toggle key's indicator light (if any) on the keyboard will be on when the key is toggled, and off when the key is untoggled.
So to return a boolean indicating if caps lock is toggled, you should only check the low order bit, otherwise your results will be wrong if the caps lock key is pressed.
You didn't include your definition of VK_TYPE, but VK_CAPITAL is defined as:
Const VK_CAPITAL = &H14
You could use something like this to check if the key is toggled:
KeyState = CBool(keys(VK_Type) And 1)
-
Apr 24th, 2002, 07:05 AM
#3
Thread Starter
Member
Problem w/other applications
My program monitors other applications and emails you through Notes when the application sucessfully or unsuccessfully completes. The problem lies when you hit the capslock while one of these programs is running and not mine. These programs also type in text into windows while running. The toggle state must get confused at this point.
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
|