-
Notifications
You must be signed in to change notification settings - Fork 10
/
main.mm
36 lines (30 loc) · 1.1 KB
/
main.mm
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
/*
* libSimulateKeyboard ( kr.iolate.simulatekeyboard )
*
* iolate ( [email protected] )
* Twitter: @iolate_e
*
* 2014. Jan. 26.
*
*/
#import "SimulateKeyboard.h"
#define PRINT_USAGE printf("[Usage]\n %s usagePage keyCode [isPress] \n\n if omit isPress, down first and up automatically.\n\n", argv[0]);
int main(int argc, char **argv, char **envp) {
if (argc != 3 && argc != 4) {
PRINT_USAGE;
return 0;
}
int usagePage = atoi(argv[1]);
int keyCode = atoi(argv[2]);
if (argc == 3) {
BOOL r = simulateKeyboardEvent(usagePage, keyCode, 1);
if (r == FALSE) NSLog(@"## SK: Failed to simulate key event %d.%d.%d", usagePage, keyCode, 1);
r = simulateKeyboardEvent(usagePage, keyCode, 0);
if (r == FALSE) NSLog(@"## SK: Failed to simulate key event %d.%d.%d", usagePage, keyCode, 0);
}else {
int isPress = atoi(argv[3]);
BOOL r = simulateKeyboardEvent(usagePage, keyCode, isPress);
if (r == FALSE) NSLog(@"## SK: Failed to simulate key event %d.%d.%d", usagePage, keyCode, isPress);
}
return 0;
}