How to know whether CapsLock is on
-
hi all, how do i know whether capslock is on? i do not mean whether is is pressed, something like this this doesnt work
class form1 'keypreview is true
inherits form
'windows forms designer generated code etcprivate CapsOn as boolean = false
protected overrides sub onkeydown(e as keyeventargs)
mybase.onkeydown(e)
if e.keycode = keys.capslock then capson = not capson
end subend class
beacuse when capslock is on before app starts stuff goes the wrong way around... does anyone have a idea? a api or something? thanks, mouzik
-
hi all, how do i know whether capslock is on? i do not mean whether is is pressed, something like this this doesnt work
class form1 'keypreview is true
inherits form
'windows forms designer generated code etcprivate CapsOn as boolean = false
protected overrides sub onkeydown(e as keyeventargs)
mybase.onkeydown(e)
if e.keycode = keys.capslock then capson = not capson
end subend class
beacuse when capslock is on before app starts stuff goes the wrong way around... does anyone have a idea? a api or something? thanks, mouzik
.Net framework didn't encapsulate all the Windows APIs yet so you will have to call the following windows api:
Private Declare Function GetKeyState Lib "user32" (ByVal virtKey As Integer) As Short
Then call it. For example:if GetKeyState(Keys.CapsLock) = 1 then capson = true
-
.Net framework didn't encapsulate all the Windows APIs yet so you will have to call the following windows api:
Private Declare Function GetKeyState Lib "user32" (ByVal virtKey As Integer) As Short
Then call it. For example:if GetKeyState(Keys.CapsLock) = 1 then capson = true
thanks rudy! although it didnt work at first, i got it working in the end:
Private Declare Function GetKeyState Lib "user32" (ByVal virtKey As Integer) As Integer
and to call it:CapsOn = CBool((GetKeyState(Keys.CapsLock) And 65535) - 65408))
thanks again!