forked from autopilot-rs/autopy-legacy
-
Notifications
You must be signed in to change notification settings - Fork 0
/
keypress.h
75 lines (56 loc) · 1.69 KB
/
keypress.h
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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
#pragma once
#ifndef KEYPRESS_H
#define KEYPRESS_H
#include "os.h"
#include "keycode.h"
#if defined(_MSC_VER)
#include "ms_stdbool.h"
#else
#include <stdbool.h>
#endif
#if defined(IS_MACOSX)
enum _MMKeyFlags {
MOD_NONE = 0,
MOD_META = kCGEventFlagMaskCommand,
MOD_ALT = kCGEventFlagMaskAlternate,
MOD_CONTROL = kCGEventFlagMaskControl,
MOD_SHIFT = kCGEventFlagMaskShift
};
typedef CGEventFlags MMKeyFlags;
#elif defined(USE_X11)
enum _MMKeyFlags {
MOD_NONE = 0,
MOD_META = Mod4Mask,
MOD_ALT = Mod1Mask,
MOD_CONTROL = ControlMask,
MOD_SHIFT = ShiftMask
};
typedef unsigned int MMKeyFlags;
#elif defined(IS_WINDOWS)
enum _MMKeyFlags {
MOD_NONE = 0,
/* These are already defined by the Win32 API */
/* MOD_ALT = 0,
MOD_CONTROL = 0,
MOD_SHIFT = 0, */
MOD_META = MOD_WIN
};
typedef unsigned int MMKeyFlags;
#endif
/* Toggles the given key down or up. */
void toggleKeyCode(MMKeyCode code, const bool down, MMKeyFlags flags);
/* Toggles the key down and then up. */
void tapKeyCode(MMKeyCode code, MMKeyFlags flags);
/* Toggles the key corresponding to the given UTF character up or down. */
void toggleKey(char c, const bool down, MMKeyFlags flags);
void tapKey(char c, MMKeyFlags flags);
/* Sends a UTF-8 string without modifiers. */
void typeString(const char *str);
/* Macro to convert WPM to CPM integers.
* (the average English word length is 5.1 characters.) */
#define WPM_TO_CPM(WPM) (unsigned)(5.1 * WPM)
/* Sends a string with partially random delays between each letter. Note that
* deadbeef_srand() must be called before this function if you actually want
* randomness. */
void typeStringDelayed(const char *str, const unsigned cpm);
#endif /* KEYPRESS_H */