一个有关 AutoHotkey 的问题。
总的来说,我希望看到,当CapsLock
处于开启状态时,按下key
会产生Shift
+ key
。我的问题几乎在 SuperUser 问题中得到解答这里以及 AutoHotkey 帖子这里。
在那里的帮助下,我现在能实现的是
- 当
CapsLock
处于开启状态时,按下a
会产生A
,其他字母亦同; - 当
CapsLock
为打开状态时,按下1
会产生!
,2
会产生@
,对于其他带有移位符号的键也同样如此,例如-
=
;
我的问题的特别之处在于我想看到这种行为通过箭头键发生。
再具体一点:
- 当
CapsLock
处于开启状态时,按Right
箭头键将产生Shift
+Right
,对于Left
、Up
和 也同样如此Down
; - 当
CapsLock
处于开启状态时,按Ctrl
+Right
会产生Ctrl
+Shift
+Right
; - 事实上,我已经重新映射了键,
LAlt & L::Send {Right}
这样Alt
+L
就会产生Right
箭头键。现在我想看看,当CapsLock
开启时,Alt
+L
会产生Shift
+Right
。
供您参考,我在这里提供了来自 AutoHotkey 论坛的 Icarus 的解决方案
#SingleInstance Force
Keys := "abcdefghijklmnopqrstuvwxyz1234567890-=[];'\,./"
Loop parse, keys
Hotkey $%A_LoopField%, PressKey
Return
PressKey:
StringReplace ThisHotkey, A_ThisHotkey, $
If( GetKeyState( "CAPSLOCK", "T" ) )
SendInput +%ThisHotkey%
Else
SendInput %ThisHotkey%
Return
ESC::ExitApp
它适用于点 1 和点 2,但我不知道如何使它适用于点 3、4 和 5 的箭头键。我尝试在上面的脚本中附加,{Right}
但Keys
它不起作用。
非常感谢您的帮助!
答案1
我自己设法解决了这个问题。太激动了!
关键在于不是当它位于的左边时,放入Right
花括号(如) 。{Right}
::
originKey
对应我自己的问题中的第3点至第5点的解决方案:
; Solution to Point 3
Left::SendInput % GetKeyState("CAPSLOCK", "T") ? "+{Left}" : "{Left}"
Up::SendInput % GetKeyState("CAPSLOCK", "T") ? "+{Up}" : "{Up}"
Down::SendInput % GetKeyState("CAPSLOCK", "T") ? "+{Down}" : "{Down}"
Right::SendInput % GetKeyState("CAPSLOCK", "T") ? "+{Right}" : "{Right}"
; Solution to Point 4
LCtrl & Left::SendInput % GetKeyState("CAPSLOCK", "T") ? "^+{Left}" : "^{Left}"
LCtrl & Up::SendInput % GetKeyState("CAPSLOCK", "T") ? "^+{Up}" : "^{Up}"
LCtrl & Down::SendInput % GetKeyState("CAPSLOCK", "T") ? "^+{Down}" : "^{Down}"
LCtrl & Right::SendInput % GetKeyState("CAPSLOCK", "T") ? "^+{Right}" : "^{Right}"
; Solution to Point 5
LAlt & J::SendInput % GetKeyState("CAPSLOCK", "T") ? "+{Left}" : "{Left}"
LAlt & I::SendInput % GetKeyState("CAPSLOCK", "T") ? "+{Up}" : "{Up}"
LAlt & K::SendInput % GetKeyState("CAPSLOCK", "T") ? "+{Down}" : "{Down}"
LAlt & L::SendInput % GetKeyState("CAPSLOCK", "T") ? "+{Right}" : "{Right}"
可能有简洁的方法来编写上述脚本,这是最受欢迎的:)
答案2
#NoEnv
#SingleInstance Force
/*
; If your keyboard has no indicator for Caps Lock, you can use this GUI:
Gui, Capslock: -caption +AlwaysOnTop
Gui, Capslock: Add, Text, x5 y5, Capslock is ON
If GetKeyState("Capslock","T")
Gui, Capslock: Show, x0 y0
*/
Keys := ["Right","Left","Up","Down","a","b","c","d","e","f","g","h","i","j","k","l","m","n","o","p","q","r","s","t","u","v","w","x","y","z","1","2","3","4","5","6","7","8","9","0","-","=","[","]",",","\",",",".","/",";"]
for each, key in Keys
Hotkey, $%key%, Shift_Key
return
Shift_Key:
ThisHotkey := StrReplace(A_ThisHotkey, "$")
If GetKeyState("Capslock","T")
SendInput, +{%ThisHotkey%}
else
SendInput, {%ThisHotkey%}
return
/*
~Capslock Up::
If GetKeyState("Capslock","T")
Gui, Capslock: Show, x0 y0
else
Gui, Capslock: cancel
return
*/