Hi,
Is there any simple way to check if Num lock/Caps lock is on or off? :ehh:
Printable View
Hi,
Is there any simple way to check if Num lock/Caps lock is on or off? :ehh:
Have a look at this sample.
Well, I don't get really much, but it seems to me that this only toggles the caps lock? ><Code:Private Sub NTToggleKeyCaps()
Call keybd_event(vbKeyCapital, _
MapVirtualKey(vbKeyCapital, 0), _
KEYEVENTF_EXTENDEDKEY Or 0, 0)
Call keybd_event(vbKeyCapital, MapVirtualKey(vbKeyCapital, 0), _
KEYEVENTF_EXTENDEDKEY Or KEYEVENTF_KEYUP, 0)
End Sub
I want to check if caps lock is on, and if it is, i want to turn it off...
And, by the way, if I only wished to toggle Caps Lock, wouldn't it just be easier to Sendkeys("{CAPSLOCK}")? ...
No, SendKeys is not reliable at all...
To check the state of say Caps key try this (btw - try to use the search engine - it's quite usefull):
Code:Option Explicit
Private Declare Function GetAsyncKeyState Lib "user32" (ByVal vKey As Long) As Integer
Private Sub Command1_Click()
Dim result As Long
result = GetAsyncKeyState(vbKeyCapital)
If result <> 0 Then
'go ahead and turn it off...
Else
'go ahead and turn it on
End If
End Sub
Why not always turn it off even if it's already off?
Rhinobull, the result is always 0 no matter if caps lock is on or off... Exept for when I press the Caps Lock-button, the result is then -32676, but that value doesn't change depending on if caps lock is on or off when i press the caps lock-button.
Yes MartinLiss, I would like to do that, but my problem is that I don't know how to just TURN THE GODDAM CAPS LOCK OFF/ON, I only know how to TOGGLE the caps lock... :pQuote:
Why not always turn it off even if it's already off?
Try this.
this should help
http://support.microsoft.com/kb/177674/EN-US/
What OS are you using? It works just fine under XP and I don't use Vista.Quote:
Originally Posted by henzino2
Thank you all guys! I combined all your help into one final solution :cool: (I've given reputation to all of you too ^^)
(Just posting it if someone's intersted)
In the module:
In the form:Code:Declare Function GetKeyState Lib "user32" (ByVal nVirtKey As Long) As Long
Declare Function MapVirtualKey Lib "user32" _
Alias "MapVirtualKeyA" _
(ByVal wCode As Long, ByVal wMapType As Long) As Long
Declare Sub keybd_event Lib "user32" _
(ByVal bVk As Byte, _
ByVal bScan As Byte, _
ByVal dwFlags As Long, _
ByVal dwExtraInfo As Long)
Public Const KEYEVENTF_KEYUP = &H2
Public Const KEYEVENTF_EXTENDEDKEY = &H1
Public Const VK_NUMLOCK = &H90
Public Const VK_CAPITAL = &H14
Function CapsLock() As Boolean
CapsLock = (GetKeyState(VK_CAPITAL) And 1 = 1)
End Function
Function NumLock() As Boolean
NumLock = (GetKeyState(VK_NUMLOCK) And 1 = 1)
End Function
Code:If NumLock() = False Then
Call keybd_event(vbKeyNumlock, _
MapVirtualKey(vbKeyNumlock, 0), _
KEYEVENTF_EXTENDEDKEY Or 0, 0)
Call keybd_event(vbKeyNumlock, MapVirtualKey(vbKeyNumlock, 0), _
KEYEVENTF_EXTENDEDKEY Or KEYEVENTF_KEYUP, 0)
End If
If CapsLock() = True Then
Call keybd_event(vbKeyCapital, _
MapVirtualKey(vbKeyCapital, 0), _
KEYEVENTF_EXTENDEDKEY Or 0, 0)
Call keybd_event(vbKeyCapital, MapVirtualKey(vbKeyCapital, 0), _
KEYEVENTF_EXTENDEDKEY Or KEYEVENTF_KEYUP, 0)
End If