-
Notifications
You must be signed in to change notification settings - Fork 48
/
Copy pathcontrolMsg.ts
227 lines (195 loc) · 5.78 KB
/
controlMsg.ts
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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
import { emit } from "@tauri-apps/api/event";
import {
AndroidKeyEventAction,
AndroidKeycode,
AndroidMetastate,
AndroidMotionEventAction,
AndroidMotionEventButtons,
} from "./android";
interface ControlMsgPayload {
msgType: ControlMsgType;
msgData?: ControlMsgData;
}
async function sendControlMsg(payload: ControlMsgPayload) {
await emit("front-command", payload);
}
export async function sendInjectKeycode(payload: InjectKeycode) {
await sendControlMsg({
msgType: ControlMsgType.ControlMsgTypeInjectKeycode,
msgData: payload,
});
}
export async function sendInjectText(payload: InjectText) {
await sendControlMsg({
msgType: ControlMsgType.ControlMsgTypeInjectText,
msgData: payload,
});
}
export async function sendInjectTouchEvent(payload: InjectTouchEvent) {
await sendControlMsg({
msgType: ControlMsgType.ControlMsgTypeInjectTouchEvent,
msgData: payload,
});
}
export async function sendInjectScrollEvent(payload: InjectScrollEvent) {
await sendControlMsg({
msgType: ControlMsgType.ControlMsgTypeInjectScrollEvent,
msgData: payload,
});
}
export async function sendBackOrScreenOn(payload: BackOrScreenOn) {
await sendControlMsg({
msgType: ControlMsgType.ControlMsgTypeBackOrScreenOn,
msgData: payload,
});
}
export async function sendExpandNotificationPanel() {
await sendControlMsg({
msgType: ControlMsgType.ControlMsgTypeExpandNotificationPanel,
});
}
export async function sendExpandSettingsPanel() {
await sendControlMsg({
msgType: ControlMsgType.ControlMsgTypeExpandSettingsPanel,
});
}
export async function sendCollapsePanels() {
await sendControlMsg({
msgType: ControlMsgType.ControlMsgTypeCollapsePanels,
});
}
export async function sendGetClipboard(payload: GetClipboard) {
await sendControlMsg({
msgType: ControlMsgType.ControlMsgTypeGetClipboard,
msgData: payload,
});
}
export async function sendSetClipboard(payload: SetClipboard) {
await sendControlMsg({
msgType: ControlMsgType.ControlMsgTypeSetClipboard,
msgData: payload,
});
}
export async function sendSetScreenPowerMode(payload: SetScreenPowerMode) {
await sendControlMsg({
msgType: ControlMsgType.ControlMsgTypeSetScreenPowerMode,
msgData: payload,
});
}
export async function sendRotateDevice() {
await sendControlMsg({
msgType: ControlMsgType.ControlMsgTypeRotateDevice,
});
}
export async function sendUhidCreate(payload: UhidCreate) {
await sendControlMsg({
msgType: ControlMsgType.ControlMsgTypeUhidCreate,
msgData: payload,
});
}
export async function sendUhidInput(payload: UhidInput) {
await sendControlMsg({
msgType: ControlMsgType.ControlMsgTypeUhidInput,
msgData: payload,
});
}
export async function sendOpenHardKeyboardSettings() {
await sendControlMsg({
msgType: ControlMsgType.ControlMsgTypeOpenHardKeyboardSettings,
});
}
export enum ControlMsgType {
ControlMsgTypeInjectKeycode, //发送原始按键
ControlMsgTypeInjectText, //发送文本,不知道是否能输入中文(估计只是把文本转为keycode的输入效果)
ControlMsgTypeInjectTouchEvent, //发送触摸事件
ControlMsgTypeInjectScrollEvent, //发送滚动事件(类似接入鼠标后滚动滚轮的效果,不是通过触摸实现的)
ControlMsgTypeBackOrScreenOn, //应该就是发送返回键
ControlMsgTypeExpandNotificationPanel, //打开消息面板
ControlMsgTypeExpandSettingsPanel, //打开设置面板(就是消息面板右侧的)
ControlMsgTypeCollapsePanels, //折叠上述面板
ControlMsgTypeGetClipboard, //获取剪切板
ControlMsgTypeSetClipboard, //设置剪切板
ControlMsgTypeSetScreenPowerMode, //设置屏幕电源模式,是关闭设备屏幕的(SC_SCREEN_POWER_MODE_OFF 和 SC_SCREEN_POWER_MODE_NORMAL )
ControlMsgTypeRotateDevice, //旋转设备屏幕
ControlMsgTypeUhidCreate, //创建虚拟设备?从而模拟真实的键盘、鼠标用的,目前没用
ControlMsgTypeUhidInput, //同上转发键盘、鼠标的输入,目前没用
ControlMsgTypeOpenHardKeyboardSettings, //打开设备的硬件键盘设置,目前没用
}
type ControlMsgData =
| InjectKeycode
| InjectText
| InjectTouchEvent
| InjectScrollEvent
| BackOrScreenOn
| GetClipboard
| SetClipboard
| SetScreenPowerMode
| UhidCreate
| UhidInput;
interface ScPosition {
x: number;
y: number;
// screen width
w: number;
// screen height
h: number;
}
interface InjectKeycode {
action: AndroidKeyEventAction;
keycode: AndroidKeycode;
// https://developer.android.com/reference/android/view/KeyEvent#getRepeatCount()
repeat: number;
metastate: AndroidMetastate;
}
export enum ScCopyKey {
SC_COPY_KEY_NONE,
SC_COPY_KEY_COPY,
SC_COPY_KEY_CUT,
}
export enum ScScreenPowerMode {
// see <https://android.googlesource.com/platform/frameworks/base.git/+/pie-release-2/core/java/android/view/SurfaceControl.java#305>
SC_SCREEN_POWER_MODE_OFF = 0,
SC_SCREEN_POWER_MODE_NORMAL = 2,
}
interface InjectText {
text: string;
}
interface InjectTouchEvent {
action: AndroidMotionEventAction;
actionButton: AndroidMotionEventButtons;
buttons: AndroidMotionEventButtons;
pointerId: number;
position: ScPosition;
pressure: number;
}
interface InjectScrollEvent {
position: ScPosition;
hscroll: number;
vscroll: number;
buttons: AndroidMotionEventButtons;
}
interface BackOrScreenOn {
action: AndroidKeyEventAction; // action for the BACK key
// screen may only be turned on on ACTION_DOWN
}
interface GetClipboard {
copyKey: ScCopyKey;
}
interface SetClipboard {
sequence: number;
text: string;
paste: boolean;
}
interface SetScreenPowerMode {
mode: ScScreenPowerMode;
}
interface UhidCreate {
id: number;
reportDescSize: number;
reportDesc: Uint8Array;
}
interface UhidInput {
id: number;
size: number;
data: Uint8Array;
}