使用 AppleScript 发送数字键的按下/按下事件 [英] Send key down / up events for number keys using AppleScript
问题描述
我需要向使用 AppleScript 的应用程序发送数字键的按键按下/按键按下事件.但是,命令:
I need to send a key down / key up event for number keys to an application using AppleScript. However, the commands:
key down "6"
delay 1
key up "6"
发送击键就好像它们来自数字键盘一样.我需要将它们解释为来自键盘顶部的数字行.
send the keystrokes as if they were coming from the number pad. I need them to be interpreted as coming from the number row at the top of the keyboard.
我也尝试过使用 (ASCII 字符 54)
代替文字,但没有成功.
I’ve also tried using (ASCII character 54)
instead of a literal, without success.
请注意,我需要发送按键 - 发送 keystroke
或 key code
不行.
Note I need key down to be sent – sending a keystroke
or key code
will not do.
推荐答案
尝试发送key down
虚拟键码而不是击键文字,即
Try sending key down
the virtual key code instead of a keystroke literal, i.e.
key down (key code <int>)
其中 int
是其中之一
1 → 18
2 → 19
3 → 20
4 → 21
5 → 23
6 → 22
7 → 26
8 → 28
9 → 25
0 → 29
您会发现
/System/Library/Frameworks/Carbon.framework/Versions/A/Frameworks/HIToolbox.framework/Versions/A/Headers/Events.h
但如果您不想进行十六进制到整数的转换,查找它们的最简单方法可能是使用 Key Codes 来自 Many Tricks,建议来自 dj bazzie wazzie.
but if you don’t feel like doing hex to integer conversion, the easiest way to look them up is probably to use Key Codes by Many Tricks, as suggested by dj bazzie wazzie.
这篇关于使用 AppleScript 发送数字键的按下/按下事件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!