AppleScript에서 키 누르기를 어떻게 자동화합니까?

키 (예 : “a”또는 “<“)의 키 누르기를 자동화 할 수 있습니까? ) Mozilla Firefox, Google Chrome 또는 Safari (이 순서대로)? 예를 들어 Mozilla Firefox에서 x 초마다 100 번의 “a”키 누르기를 자동화하고 싶습니다. x는 키를 누를 때마다 무작위로 1 초에서 10 초 사이의 값이 선택됩니다. 어떤 Applescript가 트릭을 만들 수 있나요?

또한 키보드의 각 키에 대한 모든 코드 목록은 어디에서 찾을 수 있나요?

댓글

  • 부분을 이해하지 못함 ' " 키를 누를 때마다 무작위로 선택됩니다 ".
  • @NicolasBarbulesco-각 키를 누르기 전, 임의로 선택한 길이를 1 ~ 10 초로 지연합니다. 시간.

답변

AppleScript 편집기에서 다음과 같은 스크립트 실행 :

activate application "Firefox" repeat 100 times tell application "System Events" to keystroke "a" using command down delay (random number from 0.5 to 5) end repeat 

기타 예 :

tell application "System Events" key code 123 using {shift down, command down} -- shift-command-left end 
set old to (path to frontmost application as text) tell application "Notes" reopen activate end tell tell application "System Events" to keystroke "f" using {control down, command down} delay 1 activate application old 
delay 0.5 -- time to release modifier keys if for example the script is run with command-R tell application "System Events" to tell process "Notification Center" try key down option delay 0.1 click menu bar item 1 of menu bar 1 end try key up option end tell 

키 코드 목록은 Events.h를 참조하세요.

$ grep “^ * kVK”/System/Library/Frameworks/Carbon.framework/Versions/A/Frameworks/HIToolbox.framework/Versions/A/Headers/Events.h | tr -d, | 읽는 동안 xyz; do printf “% d % s % s \ n”$ z $ z $ {x # kVK _}; done | sort -n
0 0x00 ANSI_A
1 0x01 ANSI_S
2 0x02 ANSI_D
3 0x03 ANSI_F
4 0x04 ANSI_H
5 0x05 ANSI_G
6 0x06 ANSI_Z
7 0x07 ANSI_X
8 0x08 ANSI_C
9 0x09 ANSI_V
10 0x0A ISO_Section
11 0x0B ANSI_B
12 0x0C ANSI_Q
13 0x0D ANSI_W
14 0x0E ANSI_E
15 0x0F ANSI_R
16 0x10 ANSI_Y
17 0x11 ANSI_T
18 0x12 ANSI_1
19 0x13 ANSI_2
20 0x14 ANSI_3
21 0x15 ANSI_4
22 0x16 ANSI_6
23 0x17 ANSI_5
24 0x18 ANSI_Equal
25 0x19 ANSI_9
26 0x1A ANSI_7
27 0x1B ANSI_Minus
28 0x1C ANSI_8
29 0x1D ANSI_0
30 0x1E ANSI_RightBracket
31 0x1F ANSI_O
32 0x20 ANSI_U
33 0x21 ANSI_LeftBracket
34 0x22 ANSI_I
35 0x23 ANSI_P
36 0x24 반환
37 0x25 ANSI_L
38 0x26 ANSI_J
39 0x27 ANSI_Quote
40 0x28 ANSI_K
41 0x29 ANSI_Semicolon
42 0x2A ANSI_ 백 슬래시
43 0x2B ANSI_Comma
44 0x2C ANSI_Slash
45 0x2D ANSI_N
46 0x2E ANSI_M
47 0x2F ANSI_Period
48 0x30 탭
49 0x31 공백
50 0x32 ANSI_Grave
51 0x33 삭제
53 0x35 Escape
55 0x37 명령
56 0x38 Shift
57 0x39 CapsLock
58 0x3A 옵션
59 0x3B 제어
60 0x3C RightShift
61 0x3D RightOption
62 0x3E RightControl
63 0x3F 기능
64 0x40 F17
65 0x41 ANSI_KeypadDecimal
67 0x43 ANSI_KeypadMultiply
69 0x45 ANSI_KeypadPlus
71 0x47 ANSI_KeypadClear
72 0x48 VolumeUp
73 0x49 VolumeDown
74 0x4A 음소거
75 0x4B ANSI_KeypadDivide
76 0x4C ANSI_KeypadEnter
78 0x4E ANSI_KeypadMinus
79 0x4F F18
80 0x50 F19
81 0x51 ANSI_KeypadEquals
82 0x52 ANSI_Keypad0
83 0x53 ANSI_Keypad1
84 0x54 ANSI_Keypad2
85 0x55 ANSI_Keypad3
86 0x56 ANSI_Keypad4
87 0x57 ANSI_Keypad5
88 0x58 AN SI_Keypad6
89 0x59 ANSI_Keypad7
90 0x5A F20
91 0x5B ANSI_Keypad8
92 0x5C ANSI_Keypad9
93 0x5D JIS_Yen
94 0x5E JIS_Underscore
95 0x5F JIS_KeypadComma
96 0x60 F5
br> 97 0x61 F6
98 0x62 F7
99 0x63 F3
100 0x64 F8
101 0x65 F9
102 0x66 JIS_Eisu
103 0x67 F11
104 0x68 JIS_Kana
105 0x69 F13
106 0x6A F16
107 0x6B F14
109 0x6D F10
111 0x6F F12
113 0x71 F15
114 0x72 도움말
115 0x73 홈
116 0x74 PageUp
117 0x75 ForwardDelete
118 0x76 F4
119 0x77 End
120 0x78 F2
121 0x79 PageDown
122 0x7A F1
123 0x7B LeftArrow
124 0x7C RightArrow
125 0x7D DownArrow
126 0x7E UpArrow

AppleScript를 사용하여 메뉴 항목을 클릭 할 수도 있습니다.

tell application "System Events" to tell (process 1 where frontmost is true) click menu item "Minimize" of menu 1 of menu bar item "Window" of menu bar 1 end tell 
tell application "System Events" to tell process "Finder" set frontmost to true tell menu bar item 3 of menu bar 1 click click menu item "Open With" of menu 1 end tell end tell 

댓글

  • @daviesgeek 그래서 저는 ' m 명확하지 않습니다. 옵션, 명령, H, M을 동시에 누르는 것을 어떻게 시뮬레이션 할 수 있습니까? 수정 자에 대한 키 다운을 이해하지만 H와 M을 누르는 방법은 무엇입니까?
  • 경고 : try 블록에 모든 코드가 있고 블록 뒤에 안전 키가 있는지 확인하십시오! 잡히지 않은 예외로 인해 잠시 동안 control 키를 눌렀다가 매우 답답했습니다.
  • Events.h는 이제 /Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/System/Library/Frameworks/Carbon.framework/Versions/A/Frameworks/HIToolbox.framework/Versions/A/Headers/Events.h 또는 /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/System/Library/Frameworks/Carbon.framework/Versions/A/Frameworks/HIToolbox.framework/Versions/A/Headers/Events.h에서 찾을 수 있습니다.
  • 이 목록은 훌륭합니다. 이 페이지를 자주 방문합니다. 감사합니다.
  • 실제 키보드가 연결되어있을 때만 작동하는 것이 맞습니까?

답글 남기기

이메일 주소를 발행하지 않을 것입니다. 필수 항목은 *(으)로 표시합니다