rpm
asked on
VB.Net: Reading NumLock status, even if the App doesn't have focus
Hi,
I need to read the NumLock status in VB.net.
After some Googling I found the following Class:
Public Class KeyState
Declare Function GetKeyboardState Lib "user32" Alias "GetKeyboardState" (ByVal pbKeyState() As Byte) As Long
Private KeyCode As Integer
Public Sub New(ByVal keycode As Integer)
Me.KeyCode = keycode
End Sub
Public Function KeyState() As Boolean
Dim state(256) As Byte
GetKeyboardState(state)
Return (iif(state(Me.KeyCode) = 1, True, False))
End Function
End Class
This works fine if the App has focus, but does not read the key correctly if another App as focus.
Is there a way to do this?
Thanks,
Richard
I need to read the NumLock status in VB.net.
After some Googling I found the following Class:
Public Class KeyState
Declare Function GetKeyboardState Lib "user32" Alias "GetKeyboardState" (ByVal pbKeyState() As Byte) As Long
Private KeyCode As Integer
Public Sub New(ByVal keycode As Integer)
Me.KeyCode = keycode
End Sub
Public Function KeyState() As Boolean
Dim state(256) As Byte
GetKeyboardState(state)
Return (iif(state(Me.KeyCode) = 1, True, False))
End Function
End Class
This works fine if the App has focus, but does not read the key correctly if another App as focus.
Is there a way to do this?
Thanks,
Richard
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Richard