CapsLock & Numlock status in Status Bar Panels 
Author Message
 CapsLock & Numlock status in Status Bar Panels

Can someone show me code that adds the status of a capslock & numlock as a
panel of a statusbar, including some code showing how to trap changes,
mousclicks to toggle in vb.net?

Thanks



Tue, 06 Sep 2005 04:03:26 GMT  
 CapsLock & Numlock status in Status Bar Panels
Hi Marcelo,

It's pretty complicated, because it can only be done, to my knowledge,
through the windows API.  Here's some code I use successfully:
Public Declare Function GetKeyState Lib "user32" Alias "GetKeyState" (ByVal
nVirtKey As Long) As Integer

(declare this at the top of the class statement, right after 'inherits
system.windows.forms.form')

in the form's load event:

StatusBar1.Panels.Add("Status")

StatusBar1.Panels.Add("") ' time

StatusBar1.Panels.Add("") ' capslock

StatusBar1.Panels.Add("") ' numlock

StatusBar1.Panels.Add("") ' scroll lock

StatusBar1.Panels.Add("") ' insert key

StatusBar1.Panels.Add("") ' messages

StatusBar1.Panels(0).Width = 90

StatusBar1.Panels(1).Width = 85

StatusBar1.Panels(2).Width = 115

StatusBar1.Panels(3).Width = 115

StatusBar1.Panels(4).Width = 115

StatusBar1.Panels(5).Width = 135

StatusBar1.Panels(6).Width = 335

Then add a timer:

Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Timer1.Tick

Dim capslocki, numlocki, scrolli, inserti As Integer

StatusBar1.Panels(1).Text = Now.ToShortTimeString

capslocki = GetKeyState(&H14)

numlocki = GetKeyState(&H90)

scrolli = GetKeyState(&H91)

inserti = GetKeyState(&H2D)

If capslocki And 1 Then

StatusBar1.Panels(2).Text = "CapsLock On"

Else

StatusBar1.Panels(2).Text = "CapsLock Off"

End If

If numlocki And 1 Then

StatusBar1.Panels(3).Text = "NumLock On"

Else

StatusBar1.Panels(3).Text = "NumLock Off"

End If

If scrolli And 1 Then

StatusBar1.Panels(4).Text = "Scroll Lock On"

Else

StatusBar1.Panels(4).Text = "Scroll Lock Off"

End If

If inserti And 1 Then

StatusBar1.Panels(5).Text = "Insert Mode"

Else

StatusBar1.Panels(5).Text = "Overwrite Mode"

End If

You can then use panels(6) for various messages, as appropriate.

HTH,

Bernie Yaeger



Quote:
> Can someone show me code that adds the status of a capslock & numlock as a
> panel of a statusbar, including some code showing how to trap changes,
> mousclicks to toggle in vb.net?

> Thanks



Tue, 06 Sep 2005 09:23:40 GMT  
 CapsLock & Numlock status in Status Bar Panels
Many thanks for your help



Quote:
> Hi Marcelo,

> It's pretty complicated, because it can only be done, to my knowledge,
> through the windows API.  Here's some code I use successfully:
> Public Declare Function GetKeyState Lib "user32" Alias "GetKeyState"
(ByVal
> nVirtKey As Long) As Integer

> (declare this at the top of the class statement, right after 'inherits
> system.windows.forms.form')

> in the form's load event:

> StatusBar1.Panels.Add("Status")

> StatusBar1.Panels.Add("") ' time

> StatusBar1.Panels.Add("") ' capslock

> StatusBar1.Panels.Add("") ' numlock

> StatusBar1.Panels.Add("") ' scroll lock

> StatusBar1.Panels.Add("") ' insert key

> StatusBar1.Panels.Add("") ' messages

> StatusBar1.Panels(0).Width = 90

> StatusBar1.Panels(1).Width = 85

> StatusBar1.Panels(2).Width = 115

> StatusBar1.Panels(3).Width = 115

> StatusBar1.Panels(4).Width = 115

> StatusBar1.Panels(5).Width = 135

> StatusBar1.Panels(6).Width = 335

> Then add a timer:

> Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As
> System.EventArgs) Handles Timer1.Tick

> Dim capslocki, numlocki, scrolli, inserti As Integer

> StatusBar1.Panels(1).Text = Now.ToShortTimeString

> capslocki = GetKeyState(&H14)

> numlocki = GetKeyState(&H90)

> scrolli = GetKeyState(&H91)

> inserti = GetKeyState(&H2D)

> If capslocki And 1 Then

> StatusBar1.Panels(2).Text = "CapsLock On"

> Else

> StatusBar1.Panels(2).Text = "CapsLock Off"

> End If

> If numlocki And 1 Then

> StatusBar1.Panels(3).Text = "NumLock On"

> Else

> StatusBar1.Panels(3).Text = "NumLock Off"

> End If

> If scrolli And 1 Then

> StatusBar1.Panels(4).Text = "Scroll Lock On"

> Else

> StatusBar1.Panels(4).Text = "Scroll Lock Off"

> End If

> If inserti And 1 Then

> StatusBar1.Panels(5).Text = "Insert Mode"

> Else

> StatusBar1.Panels(5).Text = "Overwrite Mode"

> End If

> You can then use panels(6) for various messages, as appropriate.

> HTH,

> Bernie Yaeger



> > Can someone show me code that adds the status of a capslock & numlock as
a
> > panel of a statusbar, including some code showing how to trap changes,
> > mousclicks to toggle in vb.net?

> > Thanks



Tue, 06 Sep 2005 14:36:31 GMT  
 
 [ 3 post ] 

 Relevant Pages 

1. Status Bar Insert Panel reports the wrong status

2. Progress bar in a Status bar panel?

3. VB5: Adding Progress Bar To Status Bar Panel?

4. Adding a Progress Bar to a Status Bar panel

5. Progress Bar in Status Bar Panel ?

6. Progress bar in status bar panel - how?

7. My StatusBarEx Control -- ProgressBar, PictureBox, Virtual Key, CapsLock, Date, Time, StatusBar, Status Bar

8. Creating a Numlock, etc. status bar

9. How you see text on status bar panel with Stye = OwnerDraw

10. How Does One Display a ProgressBar Inside A Status Bar Panel

11. Status Bar Panel Type Date/Time

12. Status bar panel resize problem

 

 
Powered by phpBB® Forum Software