执行 tell application "System Events" to keystroke "你我他 123efg"
会打出 aaa123efg
类似的 执行 tell application "System Events" to keystroke "Русский & abcdefg"
会打出 aaaaaaa & abcdefg
看少数派的教程的话keystroke这个命令是支持非 ascii 字符的, 不知道为啥所有非 ascii 字符都被替换成了 'a'
系统版本 10.15.5
1
fatestigma 2020 年 5 月 29 日
keystroke 本身需要 map 到键盘上的实际键吧,除非有每个汉字一个键的键盘布列,否则应该是不支持的。。
workaround:可以先把文字保存到剪切板,然后 keystroke "v" using command down 粘贴进去,事前可以临时保存一下剪贴板,事后恢复 |
2
fatestigma 2020 年 5 月 29 日
set _clipboard to get the clipboard
set the clipboard to "你我他 123efg" tell application "System Events" to keystroke "v" using command down set the clipboard to _clipboard |
3
Wqr2048 OP |
5
fatestigma 2020 年 5 月 29 日
@Wqr2048 #3 这样啊,那你要不看下 keyboardSetUnicodeString(stringLength:unicodeString:),好像可以用 AppleScriptObjC 来调用
|
6
LudwigWS 2020 年 6 月 1 日
@fatestigma 这个有点神奇,Mark
|
7
isaced 2022 年 4 月 8 日
通过剪贴板可以实现一个一个字符的敲击效果:
tell application "System Events" set textBuffer to "你好!" repeat with i from 1 to count characters of textBuffer set the clipboard to (character i of textBuffer) delay 0.05 keystroke "v" using command down end repeat end tell |