我在Windows 10上运行AHK以便能够使用CapsLock进行语言切换(但这不是唯一的目的)。
以下是该脚本的相关部分:
SetCapsLockState, AlwaysOff
+CapsLock::CapsLock
*CapsLock::Send, {ALTDOWN}{SHIFTDOWN}{SHIFTUP}{ALTUP}
快捷方式有点不可靠,就像它不会每三到四次切换一次语言,或类似的东西。
这可能是什么问题?
谢谢!
答案 0 :(得分:0)
尝试如下:
SetCapsLockState, off ; may work with SetCapsLockState, AlwaysOff
+CapsLock:: ; Shift CapsLock toggles CapsLock state
if GetKeyState("CapsLock", "T") = 1
SetCapsLockState, off
else if GetKeyState("CapsLock", "F") = 0
SetCapsLockState, on
return
*CapsLock::Send, {ALTDOWN}{SHIFTDOWN}{SHIFTUP}{ALTUP}
编辑:嗯。我一开始遇到问题+CapsLock
没有切换。试试这个:
SetCapsLockState, off ; may work with SetCapsLockState, AlwaysOff
+CapsLock:: ; Shift CapsLock toggles CapsLock state
if GetKeyState("CapsLock", "T") = 1
{
MsgBox CapsLock going off
SetCapsLockState, off
}
else if GetKeyState("CapsLock", "F") = 0
{
MsgBox CapsLock going on
SetCapsLockState, on
}
return
*CapsLock::
MsgBox CapsLock pressed without shift
Send, {ALTDOWN}{SHIFTDOWN}{SHIFTUP}{ALTUP}
return
看看是否按下shift + capslock
触发了封锁MsgBoxHTH,让我们知道,YMMV
答案 1 :(得分:-1)
这是来自互联网上的某个地方:
SetCapsLockState, off
+Capslock::CapsLock
*Capslock::LangSwitch(1)
*Capslock up::LangSwitch(1)
LangSwitch( iKeyDownUp=0 )
{
static tickLast
IfEqual,iKeyDownUp,1
{ tickLast=%A_TickCount%
return
}
IfEqual,iKeyDownUp,2
If( A_TickCount-tickLast>200 )
return
HKL:=DllCall("GetKeyboardLayout", "uint",GetThreadOfWindow(), "uint")
HKLnum:=DllCall("GetKeyboardLayoutList","uint",0,"uint",0)
VarSetCapacity( HKLlist, HKLnum*4, 0 )
DllCall("GetKeyboardLayoutList","uint",HKLnum,"uint",&HKLlist)
loop,%HKLnum%
{ if( NumGet( HKLlist, (A_Index-1)*4 ) = HKL )
{ HKL:=NumGet( HKLlist, mod(A_Index,HKLnum)*4 )
break
}
}
ControlGetFocus,ctl,A
SendMessage,0x50,0,HKL,%ctl%,A ;WM_INPUTLANGCHANGEREQUEST
;show traytip
LOCALE_SENGLANGUAGE=0x1001
LOCALE_SENGCOUNTRY=0x1002
VarSetCapacity( sKbd, 260, 0 )
VarSetCapacity( sCountry, 260, 0 )
DllCall("GetLocaleInfo","uint",HKL>>16,"uint",LOCALE_SENGLANGUAGE, "str",sKbd, "uint",260)
DllCall("GetLocaleInfo","uint",HKL & 0xFFFF,"uint",LOCALE_SENGCOUNTRY, "str",sCountry, "uint",260)
traytip,%sKbd%,%sCountry%
SetTimer,REMOVE_TOOLTIP,500 ;0.5 second
return
REMOVE_TOOLTIP:
SetTimer,REMOVE_TOOLTIP,off
traytip
return
}