Send key down / up events for number keys using AppleScript

早过忘川 提交于 2019-12-06 00:16:33
kopischke

Try sending key down the virtual key code instead of a keystroke literal, i.e.

key down (key code <int>)

where int is one of

1 → 18
2 → 19
3 → 20
4 → 21
5 → 23
6 → 22
7 → 26
8 → 28
9 → 25
0 → 29

You will find all virtual key codes declared in

/System/Library/Frameworks/Carbon.framework/Versions/A/Frameworks/HIToolbox.framework/Versions/A/Headers/Events.h

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.

Key down and up won't work when using system events you need key code or keystroke. Keystroke will perform it's value while key code needs the key number. Download the app 'Key Codes' from the app store to determine the correct key codes (it's free).

--activate the application (and it's first responder) first
tell application "System Events"
    keystroke "1" --value "1"
    key code 18 --1 from upper num keys
    key code 83 --1 from num pad
end tell
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!