Rabbit Remote Control
0.1.0-bate14
Toggle main menu visibility
Loading...
Searching...
No Matches
Src
Unix
KeyInjector.h
1
// Author: Kang Lin <kl222@126.com>
2
3
#ifndef KEYINJECTOR_H
4
#define KEYINJECTOR_H
5
6
#include <QObject>
7
#include <QList>
8
#include <QKeySequence>
9
10
class
KeyInjector :
public
QObject
11
{
12
Q_OBJECT
13
public
:
14
explicit
KeyInjector(QObject *parent =
nullptr
);
15
~KeyInjector();
16
17
// 必须先调用 init() 以选择后端(X11 或 uinput)
18
bool
init();
19
20
// 发送单个按键(按下并释放)
21
// key: Qt::Key value (e.g., Qt::Key_Super_L, Qt::Key_R)
22
bool
sendKey(Qt::Key key);
23
24
// 发送组合键(例如 Super + R)
25
// modifiers: list of modifier keys (e.g., Qt::Key_Super_L)
26
// key: 主键
27
bool
sendKeyCombo(
const
QList<Qt::Key> &modifiers, Qt::Key key);
28
29
// 直接发送 Super 左键(便捷)
30
bool
sendSuper();
31
32
// 清理(销毁虚拟设备等)
33
void
cleanup();
34
35
private
:
36
bool
initX11();
37
bool
initUInput();
38
void
cleanupX11();
39
void
cleanupUInput();
40
41
bool
sendKeyX11(Qt::Key key,
bool
press);
42
bool
sendKeyUInput(
int
linux_keycode,
int
value);
43
44
int
qtKeyToKeySym(Qt::Key key,
bool
*ok =
nullptr
);
// X11 keysym (XK_*), returns 0 on fail
45
int
qtKeyToLinuxKey(Qt::Key key,
bool
*ok =
nullptr
);
// Linux KEY_* code, returns 0 on fail
46
47
bool
useX11 =
false
;
48
bool
useUinput =
false
;
49
void
*x11Display =
nullptr
;
// opaque pointer to Display*
50
int
uinputFd = -1;
51
};
52
53
#endif
// KEYINJECTOR_H
Author: Kang Lin (kl222@126.com)
Copyright (c) Kang Lin Studios All Rights Reserved