Skip to content

Commit 98de664

Browse files
committed
update engigo
1 parent d236555 commit 98de664

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

52 files changed

+9132
-69
lines changed

dsserver/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,6 @@ edition = "2021"
99
dscom = {path = "../dscom"}
1010

1111
scrap = "0.5"
12-
enigo = "0.1.3"
1312

1413
vpx-codec = { path = "../libs/vpx-codec" }
14+
enigo = {path = "../libs/enigo"}

dsserver/src/key_mouse.rs

Lines changed: 54 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -1,74 +1,75 @@
11

22

3-
pub fn mouse_to_engin(key: u8) -> Option<enigo::MouseButton> {
3+
pub fn mouse_to_engin(key: u8) -> Option<enigo::Button> {
44
match key {
5-
233 => Some(enigo::MouseButton::Left),
6-
235 => Some(enigo::MouseButton::Right),
5+
0 => Some(enigo::Button::Left),
6+
1 => Some(enigo::Button::Middle),
7+
2 => Some(enigo::Button::Right),
78
_ => None,
89
}
910
}
1011

1112
pub fn key_to_enigo(key: u8) -> Option<enigo::Key> {
1213
match key {
1314
27 => Some(enigo::Key::Escape),
14-
190 => Some(enigo::Key::F1),
15-
191 => Some(enigo::Key::F2),
16-
192 => Some(enigo::Key::F3),
17-
193 => Some(enigo::Key::F4),
18-
194 => Some(enigo::Key::F5),
19-
195 => Some(enigo::Key::F6),
20-
196 => Some(enigo::Key::F7),
21-
197 => Some(enigo::Key::F8),
22-
198 => Some(enigo::Key::F9),
23-
199 => Some(enigo::Key::F10),
24-
200 => Some(enigo::Key::F11),
25-
201 => Some(enigo::Key::F12),
15+
112 => Some(enigo::Key::F1),
16+
113 => Some(enigo::Key::F2),
17+
114 => Some(enigo::Key::F3),
18+
115 => Some(enigo::Key::F4),
19+
116 => Some(enigo::Key::F5),
20+
117 => Some(enigo::Key::F6),
21+
118 => Some(enigo::Key::F7),
22+
119 => Some(enigo::Key::F8),
23+
120 => Some(enigo::Key::F9),
24+
121 => Some(enigo::Key::F10),
25+
122 => Some(enigo::Key::F11),
26+
123 => Some(enigo::Key::F12),
2627
// 19 => Some(enigo::Key::Pause), // Pause
2728
// 97 => Some(enigo::Key::Print), // Print
28-
255 => Some(enigo::Key::Delete),
29-
87 => Some(enigo::Key::End),
30-
96 => Some(enigo::Key::Layout('`')),
31-
48 => Some(enigo::Key::Layout('0')),
32-
49 => Some(enigo::Key::Layout('1')),
33-
50 => Some(enigo::Key::Layout('2')),
34-
51 => Some(enigo::Key::Layout('3')),
35-
52 => Some(enigo::Key::Layout('4')),
36-
53 => Some(enigo::Key::Layout('5')),
37-
54 => Some(enigo::Key::Layout('6')),
38-
55 => Some(enigo::Key::Layout('7')),
39-
56 => Some(enigo::Key::Layout('8')),
40-
57 => Some(enigo::Key::Layout('9')),
41-
45 => Some(enigo::Key::Layout('-')),
42-
61 => Some(enigo::Key::Layout('=')),
29+
46 => Some(enigo::Key::Delete),
30+
35 => Some(enigo::Key::End),
31+
192 => Some(enigo::Key::Unicode('`')),
32+
48 => Some(enigo::Key::Unicode('0')),
33+
49 => Some(enigo::Key::Unicode('1')),
34+
50 => Some(enigo::Key::Unicode('2')),
35+
51 => Some(enigo::Key::Unicode('3')),
36+
52 => Some(enigo::Key::Unicode('4')),
37+
53 => Some(enigo::Key::Unicode('5')),
38+
54 => Some(enigo::Key::Unicode('6')),
39+
55 => Some(enigo::Key::Unicode('7')),
40+
56 => Some(enigo::Key::Unicode('8')),
41+
57 => Some(enigo::Key::Unicode('9')),
42+
189 => Some(enigo::Key::Unicode('-')),
43+
187 => Some(enigo::Key::Unicode('=')),
4344
8 => Some(enigo::Key::Backspace),
4445
9 => Some(enigo::Key::Tab),
45-
91 => Some(enigo::Key::Layout('[')),
46-
93 => Some(enigo::Key::Layout(']')),
47-
92 => Some(enigo::Key::Layout('\\')),
48-
229 => Some(enigo::Key::CapsLock),
49-
59 => Some(enigo::Key::Layout(';')),
50-
39 => Some(enigo::Key::Layout('\'')),
46+
219 => Some(enigo::Key::Unicode('[')),
47+
221 => Some(enigo::Key::Unicode(']')),
48+
220 => Some(enigo::Key::Unicode('\\')),
49+
20 => Some(enigo::Key::CapsLock),
50+
186 => Some(enigo::Key::Unicode(';')),
51+
222 => Some(enigo::Key::Unicode('\'')),
5152
13 => Some(enigo::Key::Return),
52-
225 => Some(enigo::Key::Shift), // ShiftL
53-
44 => Some(enigo::Key::Layout(',')),
54-
46 => Some(enigo::Key::Layout('.')),
55-
47 => Some(enigo::Key::Layout('/')),
56-
226 => Some(enigo::Key::Shift), // ShiftR
57-
82 => Some(enigo::Key::UpArrow),
58-
227 => Some(enigo::Key::Control), // ControlL
59-
233 => Some(enigo::Key::Alt), // AltL
53+
16 => Some(enigo::Key::Shift), // ShiftL
54+
188 => Some(enigo::Key::Unicode(',')),
55+
190 => Some(enigo::Key::Unicode('.')),
56+
191 => Some(enigo::Key::Unicode('/')),
57+
161 => Some(enigo::Key::Shift), // ShiftR
58+
38 => Some(enigo::Key::UpArrow),
59+
17 => Some(enigo::Key::Control), // ControlL
60+
18 => Some(enigo::Key::Alt), // AltL
6061
32 => Some(enigo::Key::Space),
61-
234 => Some(enigo::Key::Alt), // AltR
62+
165 => Some(enigo::Key::Alt), // AltR
6263
// 103 => Some(enigo::Key::Menu),
63-
228 => Some(enigo::Key::Control), // ControlR
64-
81 => Some(enigo::Key::LeftArrow),
65-
84 => Some(enigo::Key::DownArrow),
66-
83 => Some(enigo::Key::RightArrow),
64+
163 => Some(enigo::Key::Control), // ControlR
65+
37 => Some(enigo::Key::LeftArrow),
66+
40 => Some(enigo::Key::DownArrow),
67+
39 => Some(enigo::Key::RightArrow),
6768
// 99 => Some(enigo::Key::Raw(45)), // Insert
68-
86 => Some(enigo::Key::PageDown),
69-
80 => Some(enigo::Key::Home),
70-
85 => Some(enigo::Key::PageUp),
71-
a if a >= 97 && a <= 122 => Some(enigo::Key::Layout((a - 97 + ('a' as u8)) as char)),
69+
34 => Some(enigo::Key::PageDown),
70+
36 => Some(enigo::Key::Home),
71+
33 => Some(enigo::Key::PageUp),
72+
a if a >= 65 && a <= 90 => Some(enigo::Key::Unicode((a - 65 + ('a' as u8)) as char)),
7273
_ => None,
7374
}
7475
}

dsserver/src/server.rs

Lines changed: 50 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,23 @@
1+
use enigo::agent::Agent;
2+
use enigo::Axis;
3+
use enigo::Coordinate;
4+
use enigo::Direction;
5+
use enigo::Enigo;
6+
use enigo::Keyboard;
7+
use enigo::Mouse;
8+
use enigo::Settings;
9+
110
use crate::key_mouse;
211
use crate::screen;
3-
use enigo::Enigo;
4-
use enigo::KeyboardControllable;
5-
use enigo::MouseControllable;
612
use std::collections::hash_map::DefaultHasher;
713
use std::hash::Hasher;
814
use std::io::Read;
915
use std::io::Write;
1016
use std::net::TcpListener;
1117
use std::net::TcpStream;
1218
use std::sync::mpsc::channel;
19+
use std::sync::LazyLock;
20+
use std::sync::Mutex;
1321
use std::thread;
1422
use std::time;
1523

@@ -105,50 +113,77 @@ pub fn run(port: u16, pwd: String) {
105113
}
106114
}
107115

116+
117+
static mut ENIGO: LazyLock<Mutex<Enigo>> =
118+
LazyLock::new(|| Mutex::new(Enigo::new(&Settings::default()).unwrap()));
119+
108120
/**
109121
* 事件处理
110122
*/
111123
fn event(mut stream: TcpStream) {
112124
let mut cmd = [0u8];
113125
let mut move_cmd = [0u8; 4];
114-
let mut enigo = Enigo::new();
115126
while let Ok(_) = stream.read_exact(&mut cmd) {
116127
match cmd[0] {
117128
dscom::KEY_UP => {
118129
stream.read_exact(&mut cmd).unwrap();
119130
if let Some(key) = key_mouse::key_to_enigo(cmd[0]) {
120-
enigo.key_up(key);
131+
unsafe {
132+
if let std::result::Result::Ok(mut eg) = ENIGO.lock() {
133+
let _ = eg.key(key, Direction::Release);
134+
}
135+
}
121136
}
122137
}
123138
dscom::KEY_DOWN => {
124139
stream.read_exact(&mut cmd).unwrap();
125140
if let Some(key) = key_mouse::key_to_enigo(cmd[0]) {
126-
enigo.key_down(key);
141+
unsafe {
142+
if let std::result::Result::Ok(mut eg) = ENIGO.lock() {
143+
let _ = eg.key(key, Direction::Press);
144+
}
145+
}
127146
}
128147
}
129148
dscom::MOUSE_KEY_UP => {
130149
stream.read_exact(&mut cmd).unwrap();
131-
if let Some(key) = key_mouse::mouse_to_engin(cmd[0]) {
132-
enigo.mouse_up(key);
150+
if let Some(button) = key_mouse::mouse_to_engin(cmd[0]) {
151+
unsafe {
152+
if let std::result::Result::Ok(mut eg) = ENIGO.lock() {
153+
let _ = eg.button(button, Direction::Release);
154+
}
155+
}
133156
}
134157
}
135158
dscom::MOUSE_KEY_DOWN => {
136159
stream.read_exact(&mut cmd).unwrap();
137-
if let Some(key) = key_mouse::mouse_to_engin(cmd[0]) {
138-
enigo.mouse_down(key);
160+
if let Some(button) = key_mouse::mouse_to_engin(cmd[0]) {
161+
unsafe {
162+
if let std::result::Result::Ok(mut eg) = ENIGO.lock() {
163+
let _ = eg.button(button, Direction::Press);
164+
}
165+
}
139166
}
140167
}
141-
dscom::MOUSE_WHEEL_UP => {
142-
enigo.mouse_scroll_y(-2);
168+
dscom::MOUSE_WHEEL_UP => unsafe {
169+
if let std::result::Result::Ok(mut eg) = ENIGO.lock() {
170+
let _ = eg.scroll(-2, Axis::Vertical);
171+
}
143172
}
144-
dscom::MOUSE_WHEEL_DOWN => {
145-
enigo.mouse_scroll_y(2);
173+
dscom::MOUSE_WHEEL_DOWN => unsafe {
174+
if let std::result::Result::Ok(mut eg) = ENIGO.lock() {
175+
let _ = eg.scroll(2, Axis::Vertical);
176+
}
146177
}
147178
dscom::MOVE => {
148179
stream.read_exact(&mut move_cmd).unwrap();
149180
let x = ((move_cmd[0] as i32) << 8) | (move_cmd[1] as i32);
150181
let y = ((move_cmd[2] as i32) << 8) | (move_cmd[3] as i32);
151-
enigo.mouse_move_to(x, y);
182+
unsafe {
183+
if let std::result::Result::Ok(mut eg) = ENIGO.lock() {
184+
let _ = eg.move_mouse(x, y, Coordinate::Abs);
185+
}
186+
}
152187
}
153188
_ => {
154189
return;
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
---
2+
name: Bug report
3+
about: Create a report to help us improve
4+
title: ""
5+
labels: bug, needs investigation
6+
assignees: ""
7+
---
8+
9+
**Describe the bug**
10+
A clear and concise description of what the bug is.
11+
12+
**To Reproduce**
13+
Steps or a minimal code example to reproduce the behavior.
14+
15+
**Expected behavior**
16+
A clear and concise description of what you expected to happen.
17+
18+
**Environment (please complete the following information):**
19+
20+
- OS: [e.g. Linux, Windows, macOS ..]
21+
- Rust [e.g. rustc --version]
22+
- Library Version [e.g. enigo 0.0.13 or commit hash fa448be ]
23+
24+
**Additional context**
25+
Add any other context about the problem here.
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
---
2+
name: Feature request
3+
about: Suggest an idea for this project
4+
title: ""
5+
labels: enhancement, needs investigation
6+
assignees: ""
7+
---
8+
9+
**Is your feature request related to a problem? Please describe.**
10+
A clear and concise description of what the problem is. Ex. I'm always frustrated when [...]
11+
12+
**Describe the solution you'd like**
13+
A clear and concise description of what you want to happen.
14+
15+
**Describe alternatives you've considered**
16+
A clear and concise description of any alternative solutions or features you've considered.
17+
18+
**Additional context**
19+
Add any other context or screenshots about the feature request here.
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
---
2+
name: Question
3+
about: Ask your Question here
4+
title: ""
5+
labels: question
6+
assignees: ""
7+
---
8+
9+
**Describe your Question**
10+
A clear and concise description of what you want to know.
11+
12+
**Describe your Goal**
13+
A clear and concise description of what you want to achieve. Consider the [XYProblem](http://xyproblem.info/)
14+
15+
**Environment (please complete the following information):**
16+
17+
- OS: [e.g. Linux, Windows, macOS ..]
18+
- Rust [e.g. rustc --version]
19+
- Library Version [e.g. enigo 0.0.13 or commit hash fa448be ]
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
name: "headless_display"
2+
description: "Creates a virtual display so e.g Firefox can start"
3+
4+
runs:
5+
using: "composite"
6+
steps:
7+
- name: Install Xvfb on Linux
8+
if: runner.os == 'Linux'
9+
run: |
10+
sudo apt-get install -y xvfb
11+
which Xvfb
12+
# Set DISPLAY env variable
13+
echo "DISPLAY=:99.0" >> $GITHUB_ENV
14+
# Create virtual display with Xvfb
15+
Xvfb :99 -screen 0 1024x768x24 > /dev/null 2>&1 &
16+
# Wait for Xvfb to start
17+
sleep 3
18+
shell: bash
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
name: "Install_deps"
2+
description: "Installs the dependencies and updates the system"
3+
4+
runs:
5+
using: "composite"
6+
steps:
7+
- name: Install dependencies
8+
run: |
9+
if [ "$RUNNER_OS" == "Linux" ]; then
10+
sudo apt-get update -q -y && sudo apt-get upgrade -y
11+
sudo apt-get install -y libxdo-dev libxkbcommon-dev libxi-dev libxtst-dev
12+
echo "$RUNNER_OS"
13+
elif [ "$RUNNER_OS" == "Windows" ]; then
14+
echo "$RUNNER_OS"
15+
elif [ "$RUNNER_OS" == "macOS" ]; then
16+
echo "$RUNNER_OS"
17+
else
18+
echo "$RUNNER_OS not supported"
19+
exit 1
20+
fi
21+
shell: bash
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
name: "screenshot"
2+
description: "Creates a screenshot"
3+
inputs:
4+
rust:
5+
description: 'Name of the Rust version'
6+
required: true
7+
platform:
8+
description: 'Name of the OS'
9+
required: true
10+
feature:
11+
description: 'Activated features'
12+
required: true
13+
14+
runs:
15+
using: "composite"
16+
steps:
17+
- name: Echo inputs
18+
shell: bash
19+
run: echo "${{ inputs.platform }}_${{ inputs.rust }}_${{ inputs.feature }}"
20+
- uses: OrbitalOwen/desktop-screenshot-action@7f96d072f57e00c3bad73e9f3282f1258262b85d
21+
if: runner.os != 'Linux'
22+
with:
23+
file-name: '${{ inputs.platform }}_${{ inputs.rust }}_${{ inputs.feature }}.jpg'
24+
- name: Take screenshot on Linux
25+
if: runner.os == 'Linux'
26+
shell: bash
27+
run: DISPLAY=$DISPLAY import -window root -quality 90 ./'${{ inputs.platform }}_${{ inputs.rust }}_${{ inputs.feature }}.jpg'
28+
- uses: actions/upload-artifact@v4
29+
if: runner.os == 'Linux'
30+
with:
31+
name: '${{ inputs.platform }}_${{ inputs.rust }}_${{ inputs.feature }}.jpg'
32+
path: '${{ inputs.platform }}_${{ inputs.rust }}_${{ inputs.feature }}.jpg'
33+
overwrite: true

0 commit comments

Comments
 (0)