summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDevaev Maxim <[email protected]>2020-08-21 00:41:33 +0300
committerDevaev Maxim <[email protected]>2020-08-21 00:41:33 +0300
commit5edb85975ffda273b09a21ee6c616517c03513db (patch)
treef6c5d9144f062a3c26d984f1bcf6805e9c95c5c6
parent1048ccace65cf950a3eef7d209d88ccbe5097976 (diff)
http hid api
-rw-r--r--kvmd/apps/kvmd/api/hid.py37
1 files changed, 37 insertions, 0 deletions
diff --git a/kvmd/apps/kvmd/api/hid.py b/kvmd/apps/kvmd/api/hid.py
index b005d6ef..6b31a38a 100644
--- a/kvmd/apps/kvmd/api/hid.py
+++ b/kvmd/apps/kvmd/api/hid.py
@@ -155,3 +155,40 @@ class HidApi:
except Exception:
return
self.__hid.send_mouse_wheel_event(delta_x, delta_y)
+
+ # =====
+
+ @exposed_http("POST", "/hid/events/send_key")
+ async def __events_send_key_handler(self, request: Request) -> Response:
+ key = valid_hid_key(request.query.get("key"))
+ if "state" in request.query:
+ state = valid_bool(request.query["state"])
+ self.__hid.send_key_events([(key, state)])
+ else:
+ self.__hid.send_key_events([(key, True), (key, False)])
+ return make_json_response()
+
+ @exposed_http("POST", "/hid/events/send_mouse_button")
+ async def __events_send_mouse_button_handler(self, request: Request) -> Response:
+ button = valid_hid_mouse_button(request.query.get("button"))
+ if "state" in request.query:
+ state = valid_bool(request.query["state"])
+ self.__hid.send_mouse_button_event(button, state)
+ else:
+ self.__hid.send_mouse_button_event(button, True)
+ self.__hid.send_mouse_button_event(button, False)
+ return make_json_response()
+
+ @exposed_http("POST", "/hid/events/send_mouse_move")
+ async def __events_send_mouse_move_handler(self, request: Request) -> Response:
+ to_x = valid_hid_mouse_move(request.query.get("to_x"))
+ to_y = valid_hid_mouse_move(request.query.get("to_y"))
+ self.__hid.send_mouse_move_event(to_x, to_y)
+ return make_json_response()
+
+ @exposed_http("POST", "/hid/events/send_mouse_wheel")
+ async def __events_send_mouse_wheel(self, request: Request) -> Response:
+ delta_x = valid_hid_mouse_wheel(request.query.get("delta_x"))
+ delta_y = valid_hid_mouse_wheel(request.query.get("delta_y"))
+ self.__hid.send_mouse_wheel_event(delta_x, delta_y)
+ return make_json_response()