Send keystrokes / ups for numeric keys using AppleScript

I need to send the down / key up keyword for numeric keys to an application using AppleScript. However, the commands:

key down "6"
delay 1
key up "6"

send keystrokes as if they were coming from a numeric keypad. I need to be interpreted as coming from a series of numbers at the top of the keyboard.

Ive also tried using (ASCII character 54)instead of a literal without success.

Note. I need to enter a key for sending - sending keystrokeor key codenot.

+3
source share
2 answers

Try sending a key downvirtual key code instead of the alphabetic character of the keystroke, 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 by Many dj bazzie wazzie.

+4

, key code . Keystroke , key code - . "Key Codes" , ( ).

--activate the application (and it 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
+1

All Articles