Link to home
Start Free TrialLog in
Avatar of andrewneely
andrewneelyFlag for United States of America

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
Avatar of Guy Hengel [angelIII / a3]
Guy Hengel [angelIII / a3]
Flag of Luxembourg image

this should give you what you need:
http://www.a1vbcode.com/snippet-3541.asp
ASKER CERTIFIED SOLUTION
Avatar of PaulHews
PaulHews
Flag of Canada 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
For querying CapsLock:
(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

Open in new window

Avatar of andrewneely

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:


    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

Open in new window