Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add relative movement plus diagonal movement for mouse keys #4

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 10 additions & 10 deletions config/mouse-config.json
Original file line number Diff line number Diff line change
@@ -1,23 +1,23 @@
{
"configured": false,
"configured": true,
"point1": {
"robot": {
"x": 0,
"y": 0
"x": 10,
"y": 10
},
"screen": {
"x": 0,
"y": 0
"x": 200,
"y": 194
}
},
"point2": {
"robot": {
"x": 0,
"y": 0
"x": 10,
"y": 40
},
"screen": {
"x": 0,
"y": 0
"x": 200,
"y": 612
}
}
}
}
10 changes: 5 additions & 5 deletions config/video-config.json
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
{
"vertical": {
"configured": false,
"timestamp": null,
"x": 0,
"configured": true,
"timestamp": "2023-12-01T12:54:06.653549+00:00",
"x": 710,
"y": 0,
"w": 0,
"h": 0
"w": 499,
"h": 1080
},
"horizontal": {
"configured": false,
Expand Down
135 changes: 116 additions & 19 deletions routes/mouse.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@
# Set up mouse
m = Mouse()

last_x_pos = -100
last_y_pos = -100

# # Config helper functions
# def app_file_path():
# # Get the app filepath
Expand All @@ -35,6 +38,16 @@
# Mouse
#
######################################################################

def debug_send_keys():
req = request.json
path = req.get("path")
control_keys = 0
hid_keycode = int(req.get("hid_keycode"))
release = bool(req.get("release"))
send_keystroke(path, control_keys, hid_keycode, release)
return Response()

def api_mouse_jiggle():
m.move_relative(10,0)
time.sleep(.5)
Expand All @@ -58,6 +71,15 @@ def api_mouse_click():
send_mouse_event('/dev/hidg1', 0x0, 0, 0, 0, 0)
return Response()

def api_mouse_button():
req = request.json
button = int(req.get("button"))
print("Mouse click button")
send_mouse_event('/dev/hidg1', button, 0, 0, 0, 0)
time.sleep(.05)
send_mouse_event('/dev/hidg1', 0x0, 0, 0, 0, 0)
return Response()

def api_mouse_move_by():
req = request.json
x_pos = req.get("x")
Expand All @@ -66,14 +88,57 @@ def api_mouse_move_by():
mouse_move_by(x_pos, y_pos)
return Response(mimetype="application/json")

def api_mouse_move_to():
global last_x_pos
global last_y_pos
req = request.json
x_pos = int(req.get("x"))
y_pos = int(req.get("y"))
#x_pos, y_pos = mapper.transformPoint(x_pos, y_pos, current_app.transformationMatrix)
print("Mouse move: (%s, %s)" % (x_pos, y_pos))
if (last_x_pos > -100 and last_y_pos > -100):
mouse_move_by(x_pos - last_x_pos, y_pos - last_y_pos)
else:
mouse_move_by(-1500, -2000)
mouse_keys_move_by(0, 4)
mouse_keys_move_by(-10, 0)
mouse_keys_move_by(4, 0)
mouse_keys_move_by(0, -10)
mouse_keys_move_by(0, 4)
mouse_keys_move_by(x_pos, y_pos)

last_x_pos = x_pos
last_y_pos = y_pos

return Response(mimetype="application/json")

def api_mouse_scroll():
req = request.json
y_distance = int(req.get("y_distance"))
delta = 100
if (y_distance < 0):
delta = -100

for x in range(abs(int(y_distance / 30))):
send_mouse_event('/dev/hidg1', 0x1, 0, 0, delta, 0)

return Response(mimetype="application/json")

def api_mouse_move_home():
global last_x_pos
global last_y_pos

print("Mouse move home")
mouse_move_by(-1500, -2500)
mouse_move_by(0, 40)
mouse_move_by(-100, 0)
mouse_move_by(40, 0)
mouse_move_by(0, -100)
mouse_move_by(0, 40)

last_x_pos = 0
last_y_pos = 0

return Response(mimetype="application/json")

def api_raw_mouse_drag_by():
Expand Down Expand Up @@ -147,27 +212,41 @@ def api_mouse_keys_click():
return Response()

def api_mouse_keys_move_to():
global last_x_pos
global last_y_pos
req = request.json
x_pos = req.get("x")
y_pos = req.get("y")
x_pos = int(req.get("x"))
y_pos = int(req.get("y"))
x_pos, y_pos = mapper.transformPoint(x_pos, y_pos, current_app.transformationMatrix)
print("Mouse keys move: (%s, %s)" % (x_pos, y_pos))
mouse_move_by(-500, -1000)
mouse_keys_move_by(0, 4)
mouse_keys_move_by(-10, 0)
mouse_keys_move_by(4, 0)
mouse_keys_move_by(0, -10)
mouse_keys_move_by(0, 4)
mouse_keys_move_by(x_pos, y_pos, transform = True)
if (last_x_pos > -100 and last_y_pos > -100):
mouse_keys_move_by(x_pos - last_x_pos, y_pos - last_y_pos)
else:
mouse_move_by(-1500, -2000)
mouse_keys_move_by(0, 4)
mouse_keys_move_by(-10, 0)
mouse_keys_move_by(4, 0)
mouse_keys_move_by(0, -10)
mouse_keys_move_by(0, 4)
mouse_keys_move_by(x_pos, y_pos)

last_x_pos = x_pos
last_y_pos = y_pos

return Response(mimetype="application/json")

def api_mouse_keys_move_home():
print("Mouse keys move home")
mouse_move_by(-500, -1000)
mouse_move_by(-1500, -2000)
mouse_keys_move_by(0, 3)
mouse_keys_move_by(-10, 0)
mouse_keys_move_by(3, 0)
mouse_keys_move_by(0, -10)
mouse_keys_move_by(0, 3)
global last_x_pos
global last_y_pos
last_x_pos = 0
last_y_pos = 0
return Response(mimetype="application/json")

def api_raw_mouse_keys_drag_by():
Expand All @@ -193,22 +272,40 @@ def mouse_keys_move_by(x, y, transform = False):
x_pos, y_pos = mapper.transformPoint(x, y, current_app.transformationMatrix)
print("Transform point to: (%s, %s)" % (x_pos, y_pos))

if x_pos < 0:
while x_pos < 0:
while x_pos != 0 or y_pos != 0:

if x_pos < 0 and y_pos < 0:
send_keystroke('/dev/hidg0', 0, KeyCodes.KEY_KP7)
x_pos += 1
y_pos += 1

elif x_pos < 0 and y_pos > 0:
send_keystroke('/dev/hidg0', 0, KeyCodes.KEY_KP1)
x_pos += 1
y_pos -= 1

elif x_pos < 0:
send_keystroke('/dev/hidg0', 0, KeyCodes.KEY_KP4)
x_pos += 1

if x_pos > 0:
while x_pos > 0:
elif x_pos > 0 and y_pos < 0:
send_keystroke('/dev/hidg0', 0, KeyCodes.KEY_KP9)
x_pos -= 1
y_pos += 1

elif x_pos > 0 and y_pos > 0:
send_keystroke('/dev/hidg0', 0, KeyCodes.KEY_KP3)
x_pos -= 1
y_pos -= 1

elif x_pos > 0:
send_keystroke('/dev/hidg0', 0, KeyCodes.KEY_KP6)
x_pos -= 1

if y_pos < 0:
while y_pos < 0:
elif y_pos < 0:
send_keystroke('/dev/hidg0', 0, KeyCodes.KEY_KP8)
y_pos += 1

if y_pos > 0:
while y_pos > 0:
elif y_pos > 0:
send_keystroke('/dev/hidg0', 0, KeyCodes.KEY_KP2)
y_pos -= 1
y_pos -= 1
7 changes: 6 additions & 1 deletion server.py
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,10 @@ def api_ping():
app.add_url_rule('/api/mouse/down', view_func=mouse.api_mouse_down, methods=['POST'])
app.add_url_rule('/api/mouse/up', view_func=mouse.api_mouse_up, methods=['POST'])
app.add_url_rule('/api/mouse/click', view_func=mouse.api_mouse_click, methods=['POST'])
app.add_url_rule('/api/mouse/button', view_func=mouse.api_mouse_button, methods=['POST'])
app.add_url_rule('/api/mouse/move/by', view_func=mouse.api_mouse_move_by, methods=['POST'])
app.add_url_rule('/api/mouse/move/to', view_func=mouse.api_mouse_move_to, methods=['POST'])
app.add_url_rule('/api/mouse/scroll', view_func=mouse.api_mouse_scroll, methods=['POST'])
app.add_url_rule('/api/mouse/move/home', view_func=mouse.api_mouse_move_home, methods=['POST'])
app.add_url_rule('/api/raw/mouse/drag/by', view_func=mouse.api_raw_mouse_drag_by, methods=['POST'])
app.add_url_rule('/api/raw/mouse/move/by', view_func=mouse.api_raw_mouse_move_by, methods=['POST'])
Expand All @@ -124,6 +127,9 @@ def api_ping():
app.add_url_rule('/api/keyboard/type', view_func=keyboard.api_keyboard_type, methods=['POST'])
app.add_url_rule('/api/keyboard/press', view_func=keyboard.api_keyboard_press, methods=['POST'])

# Debug Routes
app.add_url_rule('/api/debug/send-keys', view_func=mouse.debug_send_keys, methods=['POST'])

# Video Routes
if video_source == "hdmi":
app.add_url_rule('/stream', view_func=video.stream)
Expand Down Expand Up @@ -152,7 +158,6 @@ def api_ping():
app.add_url_rule('/raw/video-feed', view_func=video.raw_video_feed)
app.add_url_rule('/api/config/video/camera', view_func=video.api_config_video, methods=['POST'])


if __name__ == '__main__':
# Debug/Development
app.run(debug=False, host="0.0.0.0", port="5000")
2 changes: 1 addition & 1 deletion video-driver/set-up-video.sh
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
echo "1. Setting edid..."
v4l2-ctl --set-edid=file=1080p30edid --fix-edid-checksums
sleep 4
sleep 10

echo "2. Setting digital video timings..."
# Success:
Expand Down