Files
CapSpace/CapSpace.ahk
MAO Dongyang 0a5668c0ec feat: initial release of CapSpace v1.0
- Implement Smart CapsLock (Ctrl on hold, Esc on tap).
- Add virtual desktop navigation via Ctrl+Arrows.
- Add quick jump to first/last desktop via Ctrl+Up/Down.
- Fix Win key sticking issue using explicit key release and {Blind} mode.
- Optimize performance using SendEvent and Sleep tuning.
2026-02-01 15:51:22 +08:00

118 lines
2.0 KiB
AutoHotkey
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
#Requires AutoHotkey v2.0
#SingleInstance Force
/**
* CapSpace v2.0
* 描述: 将 CapsLock 变为 Smart Ctrl/Esc并增强虚拟桌面切换
*/
; --- 全局变量初始化 ---
g_LastCtrlKeyDownTime := 0
g_AbortSendEsc := false
; --- 1. 虚拟桌面切换逻辑 (修正版) ---
$^Left::SendEvent("{Blind}^#{Left}")
$^Right::SendEvent("{Blind}^#{Right}")
$^Up:: {
Loop 5 {
SendEvent("{Blind}^#{Left}")
Sleep(1)
}
; 关键:强制释放 Win 和 Ctrl防止粘滞
Send("{LWin Up}{Control Up}")
}
$^Down:: {
Loop 5 {
SendEvent("{Blind}^#{Right}")
Sleep(1)
}
; 关键:强制释放 Win 和 Ctrl
Send("{LWin Up}{Control Up}")
}
; --- 2. Smart CapsLock 核心逻辑 ---
*CapsLock:: {
global g_LastCtrlKeyDownTime, g_AbortSendEsc
; 如果 CapsLock 已经处于按下状态(长按触发的重复),直接返回
if (GetKeyState("LControl")) {
return
}
Send("{LControl Down}")
g_LastCtrlKeyDownTime := A_TickCount
g_AbortSendEsc := false
}
*CapsLock Up:: {
global g_LastCtrlKeyDownTime, g_AbortSendEsc
Send("{LControl Up}")
; 如果期间触发了其他组合键,则不发送 Esc
if (g_AbortSendEsc) {
return
}
; 判断按下时间,如果小于 250ms 则视为单击,发送 Esc
time_elapsed := A_TickCount - g_LastCtrlKeyDownTime
if (time_elapsed <= 250) {
Send("{Esc}")
}
}
; --- 3. 拦截逻辑:只要按了 Ctrl 组合键,就放弃发送 Esc ---
; 使用动态热键或通配符拦截所有常用按键
; 在 v2.0 中,我们通过一个简单的循环或特定的通配符来处理
~*^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::
~*^0::
~*^1::
~*^2::
~*^3::
~*^4::
~*^5::
~*^6::
~*^7::
~*^8::
~*^9::
~*^Space::
~*^Backspace::
~*^Delete::
~*^Enter::
~*^Tab::
~*^Up::
~*^Down::
~*^Left::
~*^Right:: {
global g_AbortSendEsc := true
}