andrewneely
asked on
Determining the status of the Insert key, caps lock and num lock
How do I determine the status of the several toggle keys (nums lock, caps lock, insert/delete keys) on the keyboard in MS VB 2005? I'm guessing that it is a simple, striaght forward matter of querying the property of an object, but I don't know which one to query.
Thanks
Thanks
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
For querying CapsLock:
(this is a READ-ONLY property...to set the state you need to use APIs such as in angelIII's link)
(this is a READ-ONLY property...to set the state you need to use APIs such as in angelIII's link)
If My.Computer.Keyboard.CapsLock Then
Debug.Print("CapsLock ON")
Else
Debug.Print("CapsLock OFF")
End If
ASKER
What's interesting is that I've been using IBM compatable computers for several decades, and have never noticed that behavior!
It looks like the BIOS does track the insert status. Unfortunately it appears that Windows ignores the status. Take a look at http://www.thescripts.com/forum/thread380429.html
The relevent parts of his code are attached:
The relevent parts of his code are attached:
Private Declare Function GetKeyboardState Lib "user32" (ByRef pbKeyState As Byte) As Integer
Const VK_INS As Short = &H2DS
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim InsState As Boolean
Dim keys(255) As Byte
GetKeyboardState(keys(0))
InsState = keys(VK_INS)
If InsState <> True Then
Label1.Text = "Overtype"
Else
Label1.Text = "Insert On"
End If
End Sub
http://www.a1vbcode.com/snippet-3541.asp