Sign in to follow this  
Followers 0
jiggunjer

Make caps lock stay off

2 posts in this topic

Hi new AutoIt user here. Trying to change my capslock into a conditional backspace, but it keeps toggling back on. What am I missing?

 

#include <WinAPISys.au3>
;#include <MsgBoxConstants.au3> ;For debugging/finding a keyboard ID value

Opt("SendAttachMode", 1)
Opt("SendCapslockMode", 0)  ;1 restores Caps to pre-send state (default!), 0 doesn't store
Send("{CapsLock off}")
HotKeySet("{CapsLock}","capsfun")
$KBL_CUSTOM = "0xF0C00409" ;My Custom Keyboard Layout code
;$KBL_US    = "0x04090409" ;US Keyboard Layout code
;$KBL_USINT = "0xF0010409" ;US-international Keyboard Layout code
;$KBL_GREEK = "0x04080408" ;Greek Keyboard Layout code


while 1
    Sleep(400)
WEnd

;--- Functions
Func capsfun()
   $handl = WinGetHandle("")
   $ID = _WinAPI_GetKeyboardLayout ( $handl ) ;gets 32bit hex value of keyboard layout
   Global $key_on
   ;MsgBox($MB_SYSTEMMODAL, "", $ID) ;Debugging
   If $ID == $KBL_CUSTOM then
      HotKeySet("{CapsLock}")
      Send("{CapsLock off}")
      Send("{CapsLock off}{BACKSPACE}{CapsLock off}") ;Apparently switching Caps off once isn't enough...
      Send("{CapsLock off}")
      HotKeySet("{CapsLock}","capsfun")
   Else
      Send("{CapsLock toggle}") ;Since the capslock isn't captured by HotKeySet this shouldn't be necessary, but it is?!
   EndIf
EndFunc

;---Bugs
;Sometimes the backspace-version actives caps lock with repeated presses (though keyboard light isn't on). Using that mode should always result in caps lock off, i.e. matching the keyboard light state.

 

Share this post


Link to post
Share on other sites



Not sure how to edit my old post, but ignore that global variable, it's a typo.

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  
Followers 0