Windows 使用自动热键(或其他方式)创建自定义键盘布局
我希望创建一个自定义键盘布局,主要用于键入unicode数学符号。我需要的符号集非常大,我提出的方案涉及多种布局和特殊组合 我输入一次`(backtick),取而代之的是一个特殊的字符,我们用*来表示。通过键入其他键,我可以得到与特定主题相关的特定键盘布局。(我想用一个特殊的符号替换回勾号,这样我就能记住它是某种控制代码。键入两次,我就得到了一个正常的回勾号) 以下是一些示例映射:Windows 使用自动热键(或其他方式)创建自定义键盘布局,windows,unicode,keyboard,autohotkey,Windows,Unicode,Keyboard,Autohotkey,我希望创建一个自定义键盘布局,主要用于键入unicode数学符号。我需要的符号集非常大,我提出的方案涉及多种布局和特殊组合 我输入一次`(backtick),取而代之的是一个特殊的字符,我们用*来表示。通过键入其他键,我可以得到与特定主题相关的特定键盘布局。(我想用一个特殊的符号替换回勾号,这样我就能记住它是某种控制代码。键入两次,我就得到了一个正常的回勾号) 以下是一些示例映射: *s -> Set theory layout: [ -> ∈ (element of)
*s -> Set theory layout:
[ -> ∈ (element of)
o -> ∅ (empty set)
*r -> General math:
s -> ∫ (integral sign)
S -> ∬ (double integral sign)
*e -> Misc operators:
8 -> ∗ (convolution asterisk)
* -> ⋆ (star operator)
*g -> Greek alphabet
键入字符(如=
)后,我可以键入其他一些特殊组合来修改该字符。例如:
*x -> Negates the previous character:
= -> ≠ (unequal)
≡ -> ≢ (negation of three line equality)
*w -> Expands the previous character:
∫ -> ∭ (triple integral)
∬ -> ⨌ (quad integral)
这些映射是助记的。我可以想象把我想要的所有符号塞进一个布局,但它是无法使用的,所以我想尝试使用这个方案或类似的东西
键盘是针对Windows环境的,但我自己为它编写键盘DLL是毫无疑问的。我调查了一下,结果太复杂了
现在,我正在研究AHK的解决方案。可以用AHK(或类似的东西)完成吗?如果是的话,你能给我举一些例子让我开始吗
我还想知道是否还有其他方法可以做到这一点
我知道微软键盘布局创造者,过去也用过,但功能还不够强大。我也知道Tavultesoft的Keyman,而且我知道它可以做我想做的事情,但是它的价格非常昂贵,所以它不是一个选项。你需要的东西肯定可以用AutoHotkey来完成 棘手的部分是:您需要动态地分配热键。前者可以通过-命令实现,后者尚未实现,可能永远也不会实现。 您可以将它们写入新的.ahk文件并单独执行该脚本,也可以使用。autohotkey.net的存储库已经关闭多年,但我找到了脚本。 要运行以下示例脚本,您需要将该脚本下载到
Hotstrings.ahk
中,并将其放在主.ahk文件所在的目录中
但是,我无法将布局更改器热键分配给
`
,因此我将其设置为ä
我知道这个网站不是一个代码提供者网络,但我对这个问题也很感兴趣
#NoEnv
SendMode Input
SetWorkingDir %A_ScriptDir%
#include Hotstrings.ahk
lastKey := ""
; KEYS OF THE NORMAL LAYOUT WHICH SHOULD BE NEGATABLE:
hotstrings("=", "_equals") ;
; CHOOSE LAYOUT OR NEGATE/EXPAND LAST CHARACTER:
:*?:ä::
; backSpacePressed: ; wtf is this? sorry just saw this now. Does not belong here, does not belong anywhere
sendRaw *
tooltip,
(
n normal layout
s set theory
r general math
x negate previous
w expand previous
{esc} cancel
), %A_CaretX%, %A_CaretY%
input, layout, L1, {Escape}, s,r,e,g,x,w
send {Backspace} ; remove the *
if layout in n,s,r,e,g,x,w
{
tooltip, %layout%, %A_CaretX%, %A_CaretY%
; RESET
if layout = n
{
reset_all_hotstrings()
; KEYS OF THE NORMAL LAYOUT WHICH SHOULD BE NEGATABLE:
hotstrings("=", "_equals")
}
; NEW LAYOUT
else if layout = s
{
reset_all_hotstrings()
; SET THEORY SHORTCUTS
hotstrings("o", "_emptySet")
hotstrings("\[", "_elementOf")
}
else if layout = r
{
reset_all_hotstrings()
; MATH SHORTCUTS
hotstrings("s", "_integral")
hotstrings("S", "_doubleIntegral")
hotstrings("=", "_identical")
}
; and so on
; ...
; EDIT PREVIOUS CHARACTER
else if layout = x
{
send {backSpace}
if lastKey = identical
sendUnicodeChar(0x2262)
else if lastKey = equals
sendUnicodeChar(0x2260)
}
; EXPAND PREVIOUS CHARACTER
else if layout = w
{
send {backSpace}
if lastKey = integral
sendUnicodeChar(0x222D)
else if lastKey = doubleIntegral
sendUnicodeChar(0x2A0C)
}
}
else
{
tooltip, cancelled, %A_CaretX%, %A_CaretY%
}
sleep, 500
tooltip
return
reset_all_hotstrings() {
hotstrings("=")
hotstrings("\[")
hotstrings("o")
hotstrings("s")
hotstrings("S")
; and so on
}
; NORMAL LAYOUT SHORTCUTS:
_equals:
sendUnicodeChar(0x003D)
lastKey = equals
return
; SPECIAL LAYOUT SHORTCUTS:
_emptySet:
;sendUnicodeChar(0x00D8)
altNumpad(0216)
; to find out numpad combination or unicode: press WIN+R, type in "charmap"
; or for unicode only, go to http://www.fileformat.info/info/unicode/category/index.htm
; (sendUnicodChar() needs 0x before the unicode string)
;altNumpad(0248)
;send Ø
;send ø
; choose whatever works best for you
lastKey = emptySet
return
_elementOf:
sendUnicodeChar(0x2208)
lastKey = elementOf
return
_integral:
sendUnicodeChar(0x222B)
lastKey = integral
return
_identical:
sendUnicodeChar(0x2261)
lastKey = identical
return
_doubleIntegral:
sendUnicodeChar(0x222C)
lastKey = doubleIntegral
return
; -------------------------------------------
altNumpad(numbers) {
stringSplit, n, numbers
setkeydelay, 100
send {alt down}
loop, %n0%
{
t := n%a_index%
send {numpad%t%}
}
send {alt up}
}
SendUnicodeChar(charCode)
{
VarSetCapacity(ki, 28 * 2, 0)
EncodeInteger(&ki + 0, 1)
EncodeInteger(&ki + 6, charCode)
EncodeInteger(&ki + 8, 4)
EncodeInteger(&ki +28, 1)
EncodeInteger(&ki +34, charCode)
EncodeInteger(&ki +36, 4|2)
DllCall("SendInput", "UInt", 2, "UInt", &ki, "Int", 28)
}
EncodeInteger(ref, val)
{
DllCall("ntdll\RtlFillMemoryUlong", "Uint", ref, "Uint", 4, "Uint", val)
}
^e::reload
很明显,还有很大的改进空间,为什么你希望你的
`
一开始就被*
替换?你这是什么意思?好吧,用一个特殊的unicode符号替换`
字符,以提醒我正在使用某种控制代码。我不知道我会使用什么奇怪的unicode符号,所以我只是说*
。仅供参考:Keyman 9和Keyman Developer 9都有免费版本。这太神奇了。你真是太棒了。这比我希望的要多得多。我在AHK完全是个新手,所以我需要一段时间才能弄明白这一点,但谢谢你。看起来我的工作已经完成了,写下了我想要的所有符号。如果你感兴趣,你可以找到我目前的布局想法。但是有些东西不在其中,比如所有组合变音符号,以及映射的扩展目标,尽管这些往往与大多数程序不兼容,并且可能无法渲染。我明白了。。在布局中,您还提到了Shift。ctrl、shift、alt、win是修饰符,afaik不能在热字符串中使用,只能在热键中使用。也许将hotsings和hotstrings.ahk库放在旁边是最好的解决方案。您可以使用上面提到的热键
命令,而不是热字符串(“,”)
。唯一的缺点:你必须手动发送{backspace}
,就像[1][这个]例子[1]天哪,我讨厌堆栈注释。我认为它会根据我键入的字符工作,比如S
而不是S
。此外,没有alt或control,只需shift(基本上是“大写字母”版本).我被其他事情转移了注意力,所以直到现在我才开始使用键盘,但我是今天写的,如果你感兴趣的话。