Code: Select all
WaitSecForCapslock()
{
CapsTime=1000 ; timer in ms (actual time is longer due to possible slowness of this code)
CapsCounter=0
Pressed=0
HotKey, Capslock, PressedKey, On
Loop
{
Sleep 10
CapsCounter+=10
If (CapsCounter>=CapsTime)
{
HotKey, Capslock, PressedKey, Off
Return 0
}
If Pressed
Return 1
}
Return
PressedKey:
Pressed=1
Return
}
*CapsLock::Return
; $ means when Sending the same key as in the hotkey, loop is prevented
; (the hotkey will not trigger itself when $ is used)
*$F1::
*$F2::
*$F3::
*$F4::
*$F5::
*$F6::
*$F7::
*$F8::
*$F9::
*$F10::
*$F11::
*$F12::
myModifier=
GetKeyState, shiftState, Shift
GetKeyState, controlState, Control
GetKeyState, winkeyState, LWin
GetKeyState, altState, Alt
ThisKeyNow := StrReplace(A_ThisHotkey, "*") ; just remove that *
ThisKeyNow := StrReplace(ThisKeyNow, "$") ; just remove that $
If ( controlState == "D" || winkeyState == "D" || altState == "D")
{
If ( shiftState == "D" )
myModifier := "+"
If ( controlState == "D" )
myModifier := myModifier . "^"
If ( winkeyState == "D" )
myModifier := myModifier . "#"
If ( altState == "D" )
myModifier := myModifier . "!"
Send %myModifier%{%ThisKeyNow%}
TrayTip %myModifier%%ThisKeyNow%,`n
Return ; stop here if other modifiers than shift was held down
}
If (shiftState == "D")
myModifier = Shift+
TrayTip, CapsLock confirms %myModifier%%ThisKeyNow%,(if in 1000ms)
If WaitSecForCapslock()
{
if (myModifier == "Shift+")
{
Send +{%ThisKeyNow%}
TrayTip, Shift+%ThisKeyNow%,`n
}
Else
{
Send {%ThisKeyNow%}
TrayTip, %ThisKeyNow%,`n
}
}
Else
TrayTip, CapsLock confirms %myModifier%%ThisKeyNow%,(timeout)
Return
About CapsLock, it's normal function is just nulled on the code. On my setup I use CapsLock for many purposes (depending on how long I hold CapsLock I get different functions). But that's another topic.