Click here to Skip to main content
15,909,953 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
What I want is if I click the NUM LK in the keyboard then it would display NUM in the status bar then if I press capslock it would display CAP but this code is not working how could I possibly do that ehhehe..... Any help will be appreciated ehehe


VB
Private Sub CheckLockKeys()
        ' If the capslock key changes then change the value of the capslock statusbarpanel.
        If My.Computer.Keyboard.CapsLock Then
            capsLock.Text = "CAP"
            capsLock.BorderStyle = Border3DStyle.Raised
        Else
            capsLock.Text = ""
            capsLock.BorderStyle = Border3DStyle.Sunken
        End If

        ' If the numlock key changes then change the value of the numlock statusbarpanel.
        If My.Computer.Keyboard.NumLock Then
            numLock.Text = "NUM"
            numLock.BorderStyle = Border3DStyle.Raised
        Else
            numLock.Text = ""
            numLock.BorderStyle = Border3DStyle.Sunken
        End If
    End Sub

    Private Sub frmMain_KeyDown(ByVal sender As System.Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles MyBase.KeyDown, MyBase.KeyDown, MyBase.KeyDown, MyBase.KeyDown, MyBase.KeyDown, MyBase.KeyDown, MyBase.KeyDown, MyBase.KeyDown
        ' Check to see if the key pressed was either of the lock keys we're interested in.
        If e.KeyCode = Keys.CapsLock Or e.KeyCode = Keys.NumLock Then
            CheckLockKeys()
        End If
    End Sub
Posted

1 solution

Add a label to a form and drop in the code below, this works fine.

VB
Private Sub Form1_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
    getKeyStates()
End Sub

Private Sub Form1_KeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles Me.KeyDown

    If e.KeyCode = Keys.CapsLock Or e.KeyCode = Keys.NumLock Then
        getKeyStates()
    End If

End Sub


Private Sub getKeyStates()
    Dim outString As String = String.Empty

    If My.Computer.Keyboard.CapsLock Then
        outString = "CAPS"
    End If

    If My.Computer.Keyboard.NumLock Then
        If outString.Length > 0 Then
            outString = outString + " | "
        End If
        outString = outString + "NUM"
    End If

    Label1.Text = outString

End Sub
 
Share this answer
 
Comments
Member 12989566 8-Feb-17 10:36am    
how to calculate and display about the current line and the current position of the cursor

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900