pickletech
IS-IT--Management
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