Does anyone have a good idea for achieving this without resorting to sending CapsLock and observing the reaction?
I'm hoping for something like a magic trick using SendMessage to the main AHK script or similar methods.
(If not, I'll have to trace every instance of SetCapsLockState in tens of thousands of lines of code. Dreadful...)
Can I determine if the Always property has been used in SetCapsLockState? Topic is solved
Can I determine if the Always property has been used in SetCapsLockState?
- English is not my native language. Please forgive any awkward expressions.
- 영어는 제 모국어가 아닙니다. 어색한 표현이 있어도 양해해 주세요.
Re: Can I determine if the Always property has been used in SetCapsLockState?
I would actually recommend using the script as in your last comment, because the script "knows". That approach is direct, straightforward, and reliable.
Re: Can I determine if the Always property has been used in SetCapsLockState? Topic is solved
You do not need to "trace every instance of SetCapsLockState". Off the top of my head, you could:
- Define your own MySetCapsLockState function and use search and replace to replace calls in your script, no "tracing" needed. Your function can call the built-in one before/after recording whether the Always mode was used.
- Define your own SetCapsLockState function and ignore the built-in one. You can implement it with GetKeyState to check the current toggle state, Send to toggle it if appropriate, and Hotkey to register/enable/disable a hotkey to suppress the key, or InputHook to suppress the key. The rest of your script can continue to call SetCapsLockState as before.
- Hook SetCapsLockState by redefining the Call property. Whenever SetCapsLockState is called, your code will run first and can record whether the Always mode was used.
Code: Select all
#Requires AutoHotkey v2.0
global CapsLockAlways := ""
SetCapsLockState.DefineProp('Call', {call: _SCLS_Call})
_SCLS_Call(scls, state) {
(scls.base.Call)(scls, state)
global CapsLockAlways := SubStr(state,7)
}
MsgBox CapsLockAlways
SetCapsLockState "AlwaysOn"
MsgBox CapsLockAlways
SetCapsLockState "AlwaysOff"
MsgBox CapsLockAlways
Code: Select all
#Requires AutoHotkey v2.1-alpha.5
global CapsLockAlways := ""
SetCapsLockState.DefineProp('Call', {call: (scls, state) {
(scls.base.Call)(scls, state)
global CapsLockAlways := SubStr(state,7)
}})
MsgBox CapsLockAlways
SetCapsLockState "AlwaysOn"
MsgBox CapsLockAlways
SetCapsLockState "AlwaysOff"
MsgBox CapsLockAlways