Skip to content

Commit

Permalink
Adding more of mouse implementation
Browse files Browse the repository at this point in the history
  • Loading branch information
mtlynch committed Aug 24, 2020
1 parent 3a1592a commit 3fb63a3
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 7 deletions.
14 changes: 12 additions & 2 deletions app/hid.py
@@ -1,5 +1,8 @@
import logging
import threading

logger = logging.getLogger(__name__)


class Error(Exception):
pass
Expand Down Expand Up @@ -55,5 +58,12 @@ def release_keys(keyboard_path):


def send_mouse_position(mouse_path, x, y):
# TODO(mtlynch): Implement this
pass
logger.info('sending %d, %d to %s', x, y, mouse_path)
buf = [0] * 5
buf[0] = 0 # TODO: implement buttons
buf[1] = x & 0xff
buf[2] = (x >> 8) & 0xff
buf[3] = y & 0xff
buf[4] = (y >> 8) & 0xff
logger.info("buf=%s", buf)
_write_to_hid_interface_with_timeout(mouse_path, buf)
7 changes: 3 additions & 4 deletions app/main.py
Expand Up @@ -85,15 +85,14 @@ def socket_keystroke(message):
socketio.emit('keystroke-received', {'success': True})


@socketio.on('mouse-movement')
@socketio.on('mouseMovement')
def socket_mouse_movement(message):
mouse_move_event = _parse_mouse_move_event(message)
try:
hid.send_mouse_position(mouse_path, mouse_move_event.x,
mouse_move_event.y)
except hid.WriteError:
# TODO
pass
except hid.WriteError as e:
logger.error('Failed to forward mouse movement: %s', e)
socketio.emit('mouse-movement-received', {'success': True})


Expand Down
2 changes: 1 addition & 1 deletion app/static/css/style.css
Expand Up @@ -155,7 +155,7 @@ button:active {

#remote-screen img {
width: 100%;
cursor: not-allowed;
cursor: none;
}

.keyboard-status {
Expand Down
11 changes: 11 additions & 0 deletions app/static/js/app.js
Expand Up @@ -262,6 +262,14 @@ function onKeyUp(evt) {
}
}

function onRemoteScreenMouseMove(evt) {
console.log(evt);
keyboardSocket.emit("mouseMovement", {
x: evt.clientX,
y: evt.clientY,
});
}

function onManualModifierButtonClicked(evt) {
toggleManualModifier(evt.target.getAttribute("modifier"));
if (evt.target.classList.contains("pressed")) {
Expand All @@ -282,6 +290,9 @@ function onDisplayHistoryChanged(evt) {

document.querySelector("body").addEventListener("keydown", onKeyDown);
document.querySelector("body").addEventListener("keyup", onKeyUp);
document
.getElementById("remote-screen")
.addEventListener("mousemove", onRemoteScreenMouseMove);
document
.getElementById("display-history-checkbox")
.addEventListener("change", onDisplayHistoryChanged);
Expand Down

0 comments on commit 3fb63a3

Please sign in to comment.