Jump to content
Sign in to follow this  

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)
        ConsoleWrite("Caps Down" & @CRLF)

Func _GetCapsLock()
    Local $ret
    $ret = DllCall("user32.dll","long","GetKeyState","long",$VK_CAPS)
    Return $ret[0]
Edited by enneract

Share this post

Link to post
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
Sign in to follow this  


Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.