Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Remote Connect to Check Caps Lock

Status
Not open for further replies.

pickletech

IS-IT--Management
Dec 20, 2004
88
0
0
US
Hello Everyone, I am writing a program to check the caps lock and num lock status on a remote machine, and change them if need be. I got it to work fine on my local machine, but was wondering how I would add a button to connect to a remote machine. This is the first program I have tried making in VB. Below is all my code so far:

Code:
Public Class frmCapsNumRemote
    Private Declare Sub keybd_event Lib "user32" (ByVal bVk As Byte, _
        ByVal bScan As Byte, ByVal dwFlags As Short, ByVal dwExtraInfo As Short)
    Private Declare Function GetKeyState Lib "user32" (ByVal nVirtKey As Short) As _
        Short
    Public Const KEYEVENTF_KEYUP = &H2
    Const vbKeyCapital = &H14
    Const vbKeyNumLock = &H90
    Dim strOrigCapsLock = False
    Dim strOrigNumLock = False


    Sub SetCapsLockKey()
        ' if the current state must be changed
        'If CBool(GetKeyState(vbKeyCapital)) <> newState Then
        ' programmatically press and release the CapsLock key
        keybd_event(vbKeyCapital, 0, 0, 0)
        keybd_event(vbKeyCapital, 0, KEYEVENTF_KEYUP, 0)
        'End If
    End Sub
    Sub SetNumLockKey()
        ' if the current state must be changed
        'If CBool(GetKeyState(vbKeyCapital)) <> newState Then
        ' programmatically press and release the CapsLock key
        keybd_event(vbKeyNumLock, 0, 0, 0)
        keybd_event(vbKeyNumLock, 0, KEYEVENTF_KEYUP, 0)
        'End If
    End Sub


    Private Sub chkBoxCapsLock_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles chkBoxCapsLock.CheckedChanged
        SetCapsLockKey()
    End Sub

    Private Sub chkBoxNumLock_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles chkBoxNumLock.CheckedChanged
        SetNumLockKey()
    End Sub

    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        
        If GetKeyState(vbKeyCapital) = 1 Then
            chkBoxCapsLock.Checked = True
            SetCapsLockKey()
        End If
        If GetKeyState(vbKeyNumLock) = 1 Then
            chkBoxNumLock.Checked = True
            SetNumLockKey()
        End If

    End Sub
End Class
 
in vb2005 you can get the state of these keys by using

My.Computer.Keyboard.CapsLock

For the remote machine thing you would need to look at remoting. but it won't be easy.

Christiaan Baes
Belgium

"My new site" - Me
 
Yeah. The above code works fine on a local computer, I just don't know how (if it is possible) to add a button that would connect to another computer.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top