2
votes

Request for Support: I modified the following AutoHotkey script previously on a Win7 Pro 64-bit system. The CapsLock key is disabled in the "On" position using this script (which is desirable), then returned to normal on-off toggle state if held for a few seconds.

I have a new Win10 64-bit system and the code no longer works. I would appreciate any suggestions and advice regarding the script below.

CapsLock::
    KeyWait, CapsLock
    GetKeyState, state, CapsLock, T
    If (A_TimeSinceThisHotkey >= 5) and !(state = "D")
        SetCapsLockState, Off
    Else
        SetCapsLockState, on
Return

The error codes returned indicated that only spaces and parenthesis are appropriate and that ,s are reserved for parameters. However, if I remove the ,s, other errors popup.

1

1 Answers

0
votes

I was not able to get the same error as you; in fact, no error came up at all. (I suspect the error is from some other portion of code not shown.) However, it also didn't operate for me as you described. I had to increase A_TimeSinceThisHotkey >= 5 to A_TimeSinceThisHotkey >= 5000 (5 seconds instead of 5 milliseconds) and change !(state = "D") to (state = "D") (looking for "on" state instead of not "on" ("off")) to make it work to how I think you're describing. My understanding is that it will lock "on" if pressed, but won't turn "off" unless pressed for a period of time (5 sec. in this case); is this correct?

Note that the GetKeyState command is deprecated. You may want to use the GetKeyState() function instead for future support. Using the function also allows you to use it in expressions, so you don't need to assign it to a variable. Anyway, this was my final code. I used the ternary operator to reduce the if-statement to one line, but this isn't necessary and will work if setup how you have it.

CapsLock::
KeyWait , CapsLock
SetCapsLockState , % ( A_TimeSinceThisHotkey >= 5000 ) && !GetKeyState( CapsLock , T ) ? 0 : 1
Return