Skip to content

Instantly share code, notes, and snippets.

@Ethkuil
Last active March 28, 2024 06:07
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Ethkuil/b06c56bc25f518de78e5a91b7cdca197 to your computer and use it in GitHub Desktop.
Save Ethkuil/b06c56bc25f518de78e5a91b7cdca197 to your computer and use it in GitHub Desktop.
Shortcuts
// 似乎还是 AHK 比较合适
// TODO 0: rewrite it with AHK
// TODO 1: add more features I'd planned
// aardio is based on Lua. So the scope is global.
(function() {
count = 0
// count 为 0 等效于 count 为 1
runWithCount = function(f) {
do {
f()
count--
} while (count > 0)
}
recoverCapsLk = function() {
key.press("CapsLk") // 抵消按 CapsLk 切换大小写效果
key.down("CapsLk") // 恢复 CapsLk键 按下状态,与现实保持一致,以便检测 CapsLk键 是否按下
}
toAlphanumeric = function() {
key.ime.setOpenStatus(false)
key.ime.setConversionMode(0) // _IME_CMODE_ALPHANUMERIC
}
toNative = function() {
key.ime.setOpenStatus(true)
key.ime.setConversionMode(1|0x400) // _IME_CMODE_NATIVE | _IME_CMODE_SYMBOL
}
changeLang = function(langName) {
// `key.ime.changeRequest` 在少数对话框里会失效,但系统设置的快捷键却可用,故改用后者
// 估计是「第三方」和「系统」的区别导致的,估计是根本性问题
// 留语言代码备用(以 im-select 查询):中文 2052,英文 1033,日文 1041
// 注意与系统设置里的实际快捷键对应
if (langName == "en") key.combine("Ctrl", "Shift", "9")
else if (langName == "zh") key.combine("Ctrl", "Shift", "8")
else if (langName == "ja") key.combine("Ctrl", "Shift", "7")
}
})();
["CapsLk"] = function(hFocus) {
return false
}
/* IM switch */
["@Shift"] = function(hFocus) {
if (key.ime.state()) toAlphanumeric() else toNative()
}
["CapsLk+c"] = function(hFocus) {
changeLang("zh")
toNative()
}
["CapsLk+e"] = function(hFocus) {
changeLang("en")
}
["CapsLk+r"] = function(hFocus) {
changeLang("ja")
toNative() // 切至平假名
}
/* input */
// 暂时还没有进一步的封装必要,而直接封装个 sendPair 的话感觉不够完美,不如不封装
["CapsLk+["] = function(hFocus) {
key.sendString("「」")
key.press("Left")
}
["CapsLk+]"] = function(hFocus) {
key.sendString("」")
}
["CapsLk+Shift+["] = function(hFocus) {
key.up("Shift")
key.sendString("『』")
key.press("Left")
}
["Shift+CapsLk+["] = function(hFocus) {
key.up("Shift")
key.sendString("『』")
key.press("Left")
}
["CapsLk+Shift+]"] = function(hFocus) {
key.sendString("』")
}
["Shift+CapsLk+]"] = function(hFocus) {
key.sendString("』")
}
/* update */
// 6, 7 are difficult to input
["CapsLk+n"] = function(hFocus) {
recoverCapsLk()
key.press("6")
}
["n"] = function(hFocus) {
if (!key.getStateX("CapsLk")) return true
key.press("6")
}
["CapsLk+m"] = function(hFocus) {
recoverCapsLk()
key.press("7")
}
["m"] = function(hFocus) {
if (!key.getStateX("CapsLk")) return true
key.press("7")
}
// Can be derived by the above
["CapsLk+Shift+n"] = function(hFocus) {
recoverCapsLk()
key.press("6")
}
["Shift+CapsLk+n"] = function(hFocus) {
recoverCapsLk()
key.press("6")
}
["Shift+n"] = function(hFocus) {
if (!key.getStateX("CapsLk")) return true
key.press("6")
}
["CapsLk+Shift+m"] = function(hFocus) {
recoverCapsLk()
key.press("7")
}
["Shift+CapsLk+m"] = function(hFocus) {
recoverCapsLk()
key.press("7")
}
["Shift+m"] = function(hFocus) {
if (!key.getStateX("CapsLk")) return true
key.press("7")
}
["CapsLk+Space"] = function(hFocus) {
recoverCapsLk()
key.press("Enter")
}
["Space"] = function(hFocus) {
if (!key.getStateX("CapsLk")) return true
key.press("Enter")
}
["CapsLk+o"] = function(hFocus) {
recoverCapsLk()
key.press("End", "Enter")
}
["o"] = function(hFocus) {
if (!key.getStateX("CapsLk")) return true
key.press("End", "Enter")
}
["CapsLk+Shift+o"] = function(hFocus) {
recoverCapsLk()
key.up("Shift")
key.press("Home", "Enter", "Up")
}
["Shift+CapsLk+o"] = function(hFocus) {
recoverCapsLk()
key.up("Shift")
key.press("Home", "Enter", "Up")
}
["Shift+o"] = function(hFocus) {
if (!key.getStateX("CapsLk")) return true
key.up("Shift")
key.press("Home", "Enter", "Up")
}
["CapsLk+x"] = function(hFocus) {
recoverCapsLk()
return function() {
runWithCount(function() {
key.press("Delete")
})
}
}
["x"] = function(hFocus) {
if (!key.getStateX("CapsLk")) return true
return function() {
runWithCount(function() {
key.press("Delete")
})
}
}
["CapsLk+'"] = function(hFocus) {
recoverCapsLk()
return function() {
runWithCount(function() {
key.press("Back")
})
}
}
["'"] = function(hFocus) {
if (!key.getStateX("CapsLk")) return true
return function() {
runWithCount(function() {
key.press("Back")
})
}}
/* navigate */
["CapsLk+p"] = function(hFocus) {
recoverCapsLk()
key.press("Home")
}
["p"] = function(hFocus) {
if (!key.getStateX("CapsLk")) return true
key.press("Home")
}
["CapsLk+;"] = function(hFocus) {
recoverCapsLk()
key.press("End")
}
[";"] = function(hFocus) {
if (!key.getStateX("CapsLk")) return true
key.press("End")
}
// Can be derived by the above.
["CapsLk+Shift+p"] = function(hFocus) {
recoverCapsLk()
key.press("Home")
}
["Shift+CapsLk+p"] = function(hFocus) {
recoverCapsLk()
key.press("Home")
}
["Shift+p"] = function(hFocus) {
if (!key.getStateX("CapsLk")) return true
key.press("Home")
}
["CapsLk+Shift+;"] = function(hFocus) {
recoverCapsLk()
key.press("End")
}
["Shift+CapsLk+;"] = function(hFocus) {
recoverCapsLk()
key.press("End")
}
["Shift+;"] = function(hFocus) {
if (!key.getStateX("CapsLk")) return true
key.press("End")
}
["CapsLk+h"] = function(hFocus) {
recoverCapsLk()
key.press("Left")
}
["h"] = function(hFocus) {
if (!key.getStateX("CapsLk")) return true // getStateX 检测的是物理按键是否按下,无视键位映射
key.press("Left")
}
["CapsLk+j"] = function(hFocus) {
recoverCapsLk()
return function() {
runWithCount(function() {
key.press("Down")
})
}
}
["j"] = function(hFocus) {
if (!key.getStateX("CapsLk")) return true
return function() {
runWithCount(function() {
key.press("Down")
})
}
}
["CapsLk+k"] = function(hFocus) {
recoverCapsLk()
return function() {
runWithCount(function() {
key.press("Up")
})
}
}
["k"] = function(hFocus) {
if (!key.getStateX("CapsLk")) return true
return function() {
runWithCount(function() {
key.press("Up")
})
}
}
["CapsLk+l"] = function(hFocus) {
recoverCapsLk()
key.press("Right")
}
["l"] = function(hFocus) {
if (!key.getStateX("CapsLk")) return true
key.press("Right")
}
// Can be derived by the above.
["CapsLk+Shift+h"] = function(hFocus) {
recoverCapsLk()
key.press("Left")
}
["Shift+CapsLk+h"] = function(hFocus) {
recoverCapsLk()
key.press("Left")
}
["Shift+h"] = function(hFocus) {
if (!key.getStateX("CapsLk")) return true // getStateX 检测的是物理按键是否按下,无视键位映射
key.press("Left")
}
["CapsLk+Shift+j"] = function(hFocus) {
recoverCapsLk()
return function() {
runWithCount(function() {
key.press("Down")
})
}
}
["Shift+CapsLk+j"] = function(hFocus) {
recoverCapsLk()
return function() {
runWithCount(function() {
key.press("Down")
})
}
}
["Shift+j"] = function(hFocus) {
if (!key.getStateX("CapsLk")) return true
return function() {
runWithCount(function() {
key.press("Down")
})
}
}
["CapsLk+Shift+k"] = function(hFocus) {
recoverCapsLk()
return function() {
runWithCount(function() {
key.press("Up")
})
}
}
["Shift+CapsLk+k"] = function(hFocus) {
recoverCapsLk()
return function() {
runWithCount(function() {
key.press("Up")
})
}
}
["Shift+k"] = function(hFocus) {
if (!key.getStateX("CapsLk")) return true
return function() {
runWithCount(function() {
key.press("Up")
})
}
}
["CapsLk+Shift+l"] = function(hFocus) {
recoverCapsLk()
key.press("Right")
}
["Shift+CapsLk+l"] = function(hFocus) {
recoverCapsLk()
key.press("Right")
}
["Shift+l"] = function(hFocus) {
if (!key.getStateX("CapsLk")) return true
key.press("Right")
}
["CapsLk+w"] = function(hFocus) {
recoverCapsLk()
key.up("w")
return function() {
runWithCount(function() {
key.combine("Ctrl", "Right")
})
}
}
["w"] = function(hFocus) {
if (!key.getStateX("CapsLk")) return true
key.up("w")
return function() {
runWithCount(function() {
key.combine("Ctrl", "Right")
})
}
}
["CapsLk+b"] = function(hFocus) {
recoverCapsLk()
key.up("b")
return function() {
runWithCount(function() {
key.combine("Ctrl", "Left")
})
}
}
["b"] = function(hFocus) {
if (!key.getStateX("CapsLk")) return true
key.up("b")
return function() {
runWithCount(function() {
key.combine("Ctrl", "Left")
})
}
}
// Can be derived by the above.
["Shift+CapsLk+w"] = function(hFocus) {
recoverCapsLk()
key.up("w")
return function() {
runWithCount(function() {
key.combine("Ctrl", "Right")
})
}
}
["CapsLk+Shift+w"] = function(hFocus) {
recoverCapsLk()
key.up("w")
return function() {
runWithCount(function() {
key.combine("Ctrl", "Right")
})
}
}
["Shift+w"] = function(hFocus) {
if (!key.getStateX("CapsLk")) return true
key.up("w")
return function() {
runWithCount(function() {
key.combine("Ctrl", "Right")
})
}
}
["CapsLk+Shift+b"] = function(hFocus) {
recoverCapsLk()
key.up("b")
return function() {
runWithCount(function() {
key.combine("Ctrl", "Left")
})
}
}
["Shift+CapsLk+b"] = function(hFocus) {
recoverCapsLk()
key.up("b")
return function() {
runWithCount(function() {
key.combine("Ctrl", "Left")
})
}
}
["Shift+b"] = function(hFocus) {
if (!key.getStateX("CapsLk")) return true
key.up("b")
return function() {
runWithCount(function() {
key.combine("Ctrl", "Left")
})
}
}
["CapsLk+d"] = function(hFocus) {
recoverCapsLk()
return function() {
runWithCount(function() {
for (i = 0; 6) key.press("Down")
})
}
}
["d"] = function(hFocus) {
if (!key.getStateX("CapsLk")) return true
return function() {
runWithCount(function() {
for (i = 0; 6) key.press("Down")
})
}
}
["CapsLk+u"] = function(hFocus) {
recoverCapsLk()
return function() {
runWithCount(function() {
for (i = 0; 6) key.press("Up")
})
}
}
["u"] = function(hFocus) {
if (!key.getStateX("CapsLk")) return true
return function() {
runWithCount(function() {
for (i = 0; 6) key.press("Up")
})
}
}
/* visual */
// select current line
["CapsLk+a"] = function(hFocus) {
recoverCapsLk()
key.press("Home")
key.combine("Shift", "End")
}
["a"] = function(hFocus) {
if (!key.getStateX("CapsLk")) return true
key.press("Home")
key.combine("Shift", "End")
}
/* count */
["Esc"] = function(hFocus) {
if (count == 0) return true
count = 0
}
["CapsLk+1"] = function(hFocus) { recoverCapsLk(); count = 1; }
["CapsLk+2"] = function(hFocus) { recoverCapsLk(); count = 2; }
["CapsLk+3"] = function(hFocus) { recoverCapsLk(); count = 3; }
["CapsLk+4"] = function(hFocus) { recoverCapsLk(); count = 4; }
["CapsLk+5"] = function(hFocus) { recoverCapsLk(); count = 5; }
["CapsLk+6"] = function(hFocus) { recoverCapsLk(); count = 6; }
["CapsLk+7"] = function(hFocus) { recoverCapsLk(); count = 7; }
["CapsLk+8"] = function(hFocus) { recoverCapsLk(); count = 8; }
["CapsLk+9"] = function(hFocus) { recoverCapsLk(); count = 9; }
["1"] = function(hFocus) {
if (!key.getStateX("CapsLk")) return true
count = 1
}
["2"] = function(hFocus) {
if (!key.getStateX("CapsLk")) return true
count = 2
}
["3"] = function(hFocus) {
if (!key.getStateX("CapsLk")) return true
count = 3
}
["4"] = function(hFocus) {
if (!key.getStateX("CapsLk")) return true
count = 4
}
["5"] = function(hFocus) {
if (!key.getStateX("CapsLk")) return true
count = 5
}
["6"] = function(hFocus) {
if (!key.getStateX("CapsLk")) return true
count = 6
}
["7"] = function(hFocus) {
if (!key.getStateX("CapsLk")) return true
count = 7
}
["8"] = function(hFocus) {
if (!key.getStateX("CapsLk")) return true
count = 8
}
["9"] = function(hFocus) {
if (!key.getStateX("CapsLk")) return true
count = 9
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment