-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathApp.js
More file actions
185 lines (170 loc) · 4.77 KB
/
App.js
File metadata and controls
185 lines (170 loc) · 4.77 KB
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
import React, { useState, useRef } from 'react';
import {
View,
PanResponder,
TouchableOpacity,
StyleSheet,
Text,
} from 'react-native';
import io from 'socket.io-client';
const socket = io('http://192.168.0.103:3000');
const App = () => {
const [joystickPosition, setJoystickPosition] = useState({ x: 0, y: 0 });
const [isDragging, setIsDragging] = useState(false);
const joystickRadius = 75;
const cursorRadius = 25;
const maxOffset = joystickRadius - cursorRadius;
const panResponder = useRef(
PanResponder.create({
onStartShouldSetPanResponder: () => true,
onPanResponderGrant: () => {
setIsDragging(true);
},
onPanResponderMove: (_, gestureState) => {
let { dx, dy } = gestureState;
// Constrain the cursor within the joystick container
const distance = Math.sqrt(dx * dx + dy * dy);
if (distance > maxOffset) {
const angle = Math.atan2(dy, dx);
dx = maxOffset * Math.cos(angle);
dy = maxOffset * Math.sin(angle);
}
setJoystickPosition({ x: dx, y: dy });
socket.emit('mousemove', { dx, dy });
},
onPanResponderRelease: () => {
setJoystickPosition({ x: 0, y: 0 });
setIsDragging(false);
},
})
).current;
const handleLeftClick = () => {
socket.emit('click', 'left');
};
const handleRightClick = () => {
socket.emit('click', 'right');
};
const handleScrollUp = () => {
socket.emit('scroll', { key: 'up', hold: true });
};
const handleScrollDown = () => {
socket.emit('scroll', { key: 'down', hold: true });
};
const handleScrollRelease = () => {
socket.emit('scroll', { key: '', hold: false });
};
const monitor1Select = () => {
socket.emit('monitor1');
};
const monitor2Select = () => {
socket.emit('monitor2');
};
const monitor3Select = () => {
socket.emit('monitor3');
};
return (
<View style={styles.container}>
<View style={{ flexDirection: 'row' }}>
<TouchableOpacity style={styles.mouseButton} onPress={handleLeftClick}>
<Text style={styles.buttonText}>Left Click</Text>
</TouchableOpacity>
<View style={styles.joystickContainer} {...panResponder.panHandlers}>
<View
style={[
styles.cursor,
{
transform: [
{ translateX: joystickPosition.x },
{ translateY: joystickPosition.y },
],
},
]}
/>
</View>
<TouchableOpacity style={styles.mouseButton} onPress={handleRightClick}>
<Text style={styles.buttonText}>Right Click</Text>
</TouchableOpacity>
</View>
<View style={{ flexDirection: 'row' }}>
<TouchableOpacity
style={styles.scrollButton}
onPressIn={handleScrollUp}
onPressOut={handleScrollRelease}
>
<Text style={styles.buttonText}>Scroll Up</Text>
</TouchableOpacity>
<TouchableOpacity
style={styles.scrollButton}
onPressIn={handleScrollDown}
onPressOut={handleScrollRelease}
>
<Text style={styles.buttonText}>Scroll Down</Text>
</TouchableOpacity>
</View>
<View style={{ flexDirection: 'row' }}>
<TouchableOpacity style={styles.button} onPress={monitor2Select}>
<Text style={styles.buttonText}>monitor 2</Text>
</TouchableOpacity>
<TouchableOpacity style={styles.button} onPress={monitor1Select}>
<Text style={styles.buttonText}>monitor 1</Text>
</TouchableOpacity>
<TouchableOpacity style={styles.button} onPress={monitor3Select}>
<Text style={styles.buttonText}>monitor 3</Text>
</TouchableOpacity>
</View>
</View>
);
};
const styles = StyleSheet.create({
container: {
flex: 1,
backgroundColor: '#fff',
alignItems: 'center',
justifyContent: 'center',
},
joystickContainer: {
width: 150,
height: 150,
borderRadius: 75,
backgroundColor: '#eee',
alignItems: 'center',
justifyContent: 'center',
},
cursor: {
width: 50,
height: 50,
backgroundColor: 'red',
borderRadius: 25,
position: 'absolute',
},
buttonContainer: {
flexDirection: 'row',
flexWrap: 'wrap',
marginTop: 20,
},
mouseButton: {
backgroundColor: '#ddd',
padding: 10,
marginHorizontal: 5,
marginVertical: 10,
borderRadius: 5,
},
scrollButton: {
backgroundColor: '#ddd',
padding: 40,
marginHorizontal: 5,
marginVertical: 10,
borderRadius: 5,
},
button: {
backgroundColor: '#ddd',
padding: 10,
marginHorizontal: 5,
marginVertical: 10,
borderRadius: 5,
},
buttonText: {
fontWeight: 'bold',
},
});
export default App;