我一直试图找到重新映射键盘并发送5位十六进制unicode字符的方法,此处描述的方法:ahk Send仅支持4位十六进制代码{U + nnnn},我知道在过去,autohotkey本身并不支持unicode所以需要一些功能才能做到这一点,也许这就是我的解决方案。
示例:
#If GetKeyState("CapsLock","T")
+u::Send {U+1D4B0}
结果是풰而不是,而풰的代码是{U + D4B0},这意味着AHK只读取最后4位数字。即使我需要制作新功能来实现这一目标,我该如何解决呢?
由于
-Mark
答案 0 :(得分:2)
大于0xFFFF的Unicode值必须编码为两个代理项对:
+u:: SendInput ,{U+D835}{U+DCB0}
以下是将范围为0x10000到0x10FFFF的Unicode 代码点转换为代理对的算法,从wikipedia转述:
首先从代码点中减去0x10000,得到范围为0xFFFFF的数字。
然后将数字右移10位并向其添加0xD800以获得高代理。
取 number 的最低十位并向其添加0xDC00以获得低代理
答案 1 :(得分:0)
我从上面拿了2501的解决方案,然后把它变成了一个有效的ahk脚本。几个月来我一直在寻找这个解决方案!
+u:: FUNC_SEND_UNICODE( 0x1D4B0 )
FUNC_SEND_UNICODE(func_args)
{
/*
;commented out proof of concept code:
str := ""
u1 := Chr( 0xD835 )
u2 := Chr( 0xDCB0 )
str := u1 . u2
bk := clipboard
clipboard := str
send, ^v
sleep,200
clipboard := bk
*/
;bk == "clipboard [B]ac[K]up
bk := clipboard
;chunk of data that needs to be cut into
;two chunks.
ful := func_args + 0
/* commented out testing code, using original
sample input of stack overflow post
;msgbox,ful:[%ful%]
;for testing. Expecting input to be equal to
;the value in the post.
if(ful != 0x1D4B0 ){
msgbox,"[WHATTHEHECK]"
}
*/
;Subtract 0x10000 from ful, gets number
;in range(rng) 0x0 to 0xFFFFFF inclusive
rng := ful - 0x10000
if(rng > 0xFFFFF)
{
msgBox,[Step1 Resulted In Out Of Range]
}
;Do shifting and masking, then check to make
;sure the value is in the expected range:
big_shif := (rng >> 10)
lit_mask := (rng & 0x3FF)
if(big_shif > 0x3FF)
{
msgBox,[MATH_ERROR:big_shif]
}
if(lit_mask > 0x3FF)
{
msgBox,[MATH_ERROR:lit_mask]
}
big := big_shif + 0xD800
lit := lit_mask + 0xDC00
if(big < 0xD800 || big >= 0xDBFF){
msgBox, [HIGH_SURROGATE_OUT_OF_BOUNDS]
}
if(lit < 0xDC00 || lit >= 0xDFFF){
msgBox, [LOW_SURROGATE_OUT_OF_BOUNDS]
}
;Convert code points to actual characters:
u1 := Chr( big )
u2 := Chr( lit )
;concatentate those two characters to
;create our final surrogate output:
str := u1 . u2
;set it equal to clipboard, and send
;the clipboard. This is a hack.
;send,%str% works fine in google chrome,
;but fails in notepad++ for some reason.
;tried appending EOF, STX, ETX control codes
;along with output, but to no effect.
clipboard := str
send, ^v
;Must sleep before restoring clipboard,
;otherwise, the clipboard will get
;overwritten before ctrl+v has the chance
;to output the character. You'll end up just
;pasting whatever was originally on the
;clipboard.
sleep,200
clipboard := bk
return
}
答案 2 :(得分:0)
2501's answer的实现。
;u
;
或 Return );
终止时结束:?:`;u::
Input, keys, , `;
if (StrLen(keys) < 5)
Send {U+%keys%}
else {
keys := "0x" + keys
num := keys - 0x10000
w1 := Format("{:x}", (num >> 10) + 0xD800)
w2 := Format("{:x}", (num & 1023) + 0xDC00)
Send {U+%w1%}{U+%w2%}
}
return
供参考:
答案 3 :(得分:-1)
从互联网上的某个地方:sendunicodechar(0x1D4B0)
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)
}
修改。可能已经失去了来源的bc。我根本不知道我从哪里得到它。但是几年前我使用它时,它完美无缺。