Jump to content

changing capslock state


Recommended Posts

I'm trying write a script to disable capslock as soon as the button is not actually being held down. I found the following function will return 0 when capslock is toggled off, 1 when it is toggled on, and some other number (varies), when it is physically held down.

However, Send("{CAPSLOCK off}") or any variant does not seem to work to actually change the capslock state.

Is there any other method to do it?

I'd also like to hook the capslock key so I don't have to poll, but I guess that might be awful close to keylogger territory, so I doubt I will get answers on that.

*edit* nevermind, got it.

#include <WinAPI.au3>

$VK_CAPS = 0x14

While 1     
    $test = _GetCapsLock()
    If $test = 1 Then
        ConsoleWrite("Caps On" & @CRLF)     
    ElseIf $test = 0 Then
        ConsoleWrite("Caps Off" & @CRLF)
    Else
        ConsoleWrite("Caps Down" & @CRLF)
    EndIf
    
    Sleep(500)
WEnd

Func _GetCapsLock()
    Local $ret
    $ret = DllCall("user32.dll","long","GetKeyState","long",$VK_CAPS)
    Return $ret[0]
EndFunc
Edited by enneract
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...