Well, I did get it to run and change the colors. However
none of the keys seemed to toggle. Here is what I wrote:
*****************************************
Public Const VK_CAPITAL = &H14
Private Declare Function GetKeyboardState Lib "user32" _
(ByVal pbKeyState As Byte) As Long
Private Declare Function SetKeyboardState Lib "user32" _
(ByVal lppbKeyState As Byte) As Long
Const VK_NUMLOCK = &H90
Const VK_SCROLL = &H91
'Const VK_CAPITAL = &H14
Private Sub Form_Load()
Timer1.Enabled = False
Timer1.Interval = 50
Call Toggle(7)
Call Toggle(7)
End Sub
Private Sub Command1_Click(ByVal Index As Integer)
MsgBox(2 ^ Index)
Call Toggle(2 ^ Index)
End Sub
Private Sub Timer1_Timer()
Call Toggle(Rnd() * 8)
End Sub
Private Sub Toggle(ByVal Key As Integer)
If Key And 1 Then
If ToggleKey(VK_NUMLOCK) Then
Me.lblNumLock.BackColor =
System.Drawing.Color.Aquamarine
Else
Me.lblNumLock.BackColor =
System.Drawing.Color.RoyalBlue
End If
End If
If Key And 2 Then
If ToggleKey(VK_CAPITAL) Then
Me.lblCapsLock.BackColor =
System.Drawing.Color.Aquamarine
Else
Me.lblCapsLock.BackColor =
System.Drawing.Color.RoyalBlue
End If
End If
If Key And 4 Then
If ToggleKey(VK_SCROLL) Then
Me.lblScrollLock.BackColor =
System.Drawing.Color.Aquamarine
Else
Me.lblScrollLock.BackColor =
System.Drawing.Color.RoyalBlue
End If
End If
End Sub
Private Function ToggleKey(ByVal Key As Byte) As Boolean
Dim State As Boolean
Dim Keys(255) As Byte
Call GetKeyboardState(Keys(0))
State = Keys(Key)
If State <> True Then
Keys(Key) = 1
Else
Keys(Key) = 0
End If
Call SetKeyboardState(Keys(0))
ToggleKey = Not State
End Function
Private Sub Check1_CheckedChanged(ByVal sender As
System.Object, ByVal e As System.EventArgs) Handles
Check1.CheckedChanged
If Check1.Checked = True Then
Timer1.Enabled = True
Else
Timer1.Enabled = False
End If
End Sub
Private Sub btnNumLock_Click(ByVal sender As
System.Object, ByVal e As System.EventArgs) Handles
btnNumLock.Click
Call Command1_Click(0)
End Sub
Private Sub btnCaps_Click(ByVal sender As
System.Object, ByVal e As System.EventArgs) Handles
btnCaps.Click
Call Command1_Click(1)
End Sub
Private Sub btnScroll_Click(ByVal sender As
System.Object, ByVal e As System.EventArgs) Handles
btnScroll.Click
Call Command1_Click(2)
End Sub
**********************************************
Any ideas?
Steven