Click to See Complete Forum and Search --> : detecting the keyboard scroll lock state (example)


vb.elmar
October 20th, 2001, 06:09 AM
Hello
i need a function to detect the "scroll lock state".

The state is ON if the keyboard LED is ON, and
the state is OFF if the keyboard LED is OFF.

The code below works, but when starting another
application like notepad, vb loses the focus
and the scroll lock state no more
is displayed by my vb program.

It seems that the Function "GetKeyboardState"
does not work over vb process boundaries.

But what API can i use??

Using the api (GetAsyncKeyState)
i can detect the scroll lock state
when notepad is started too, (so it works
over vb process boundaries!!), but GetAsyncKeyState
only detects if a key is pressed at this moment
or not. It detects not the state (is the keyboard
LED OFF or ON?).

GetKeyState or GetKeyboardState **can** detect the
scroll lock state.

Can i detect the state by reading an i/o port
or any other method?

================================
needs 1 timer on a form
================================
Private Declare Function GetKeyboardState Lib "user32" _
(pbKeyState As Byte) As Long

Const VK_NUMLOCK = &H90
Const VK_SCROLL = &H91
Const VK_CAPITAL = &H14
Private Sub Form_Load()
Timer1.Interval = 50
End Sub
Private Sub Timer1_Timer()
Dim State As Boolean
Dim Keys(0 To 255) As Byte

Call GetKeyboardState(Keys(0))
State = Keys(VK_SCROLL)
Caption = State & " " & Rnd
End Sub