1
votes

Request for Support: I modified the following AutoHotkey script (found within the forum) to set the CapsLock Key to the "On" position for a db table (PhD research project) that I am working on. The CapsLock key is disabled in the "On" position using this script, which is desirable; however, no matter how long the CapsLock Key is depressed (I am using Win7), the script functionality is not broken and I must exit AutoHotkey to return the CapsLock Key to a normal on-off toggle state.

I would appreciate any suggested modifications re the script below with regard to breaking the script "ON" loop if the CapsLock key is depressed from more than a few seconds. I am a new new forum user/novice programmer and while I am sure that the scripting solution is a simple matter, I am at a loss as to how best to modify the script code further to accomplish the program break sequence. Advice or suggestions would be appreciated.

;Disable modified Caps Lock Key Script
*CapsLock::Return
;Hold Caps Lock for approximately 1 second to enable, tap to disable
CapsLock::
{
SetCapsLockState, On
Return
}
Count=0
While GetKeyState("CapsLock", "P")
{
Count++
Sleep, 1
If Count > 5
{
Send, {CapsLock}
Break
}
}
KeyWait, CapsLock
Return
3
please mark one of the answers as correct. It just helps keep things organized :-)Brigand

3 Answers

2
votes

This script enables CapsLock if held for more than a second and turns it off with any press after that.

CapsLock::
    KeyWait, CapsLock
    GetKeyState, state, CapsLock, T
    If (A_TimeSinceThisHotkey >= 1000) and !(state = "D")
        SetCapsLockState, On
    Else
        SetCapsLockState, Off
Return
1
votes

Maybe the best option would be for you toggle state of this key after its released? For example:

SetStoreCapslockMode, Off
CapsLock::
   KeyWait, CapsLock
   If A_TimeSinceThisHotkey>=1000 ; check an condition here
      Send, {CapsLock}
   Return
0
votes

Not sure why (can you enlighten?), but this modification works perfectly, but the toggle sequence is Ctrl + CapsLock to toggle on-off.

;This script enables CapsLock to be locked in the on or off position. Use Ctrl + CapsLock to control whether the lock is enabled for uppercase or lower case. Pressing the CapLock key alone has no effect when extensive use of the Tab key is underway.

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