mirror of
https://github.com/mofeng-git/One-KVM.git
synced 2025-12-12 01:00:29 +08:00
pikvm/pikvm#1536: kvmd: Added new API /hid/events/send_shortcut
This commit is contained in:
parent
6df1e55ffc
commit
2c36d86075
@ -23,6 +23,7 @@
|
|||||||
import os
|
import os
|
||||||
import stat
|
import stat
|
||||||
import functools
|
import functools
|
||||||
|
import itertools
|
||||||
import struct
|
import struct
|
||||||
|
|
||||||
from typing import Iterable
|
from typing import Iterable
|
||||||
@ -47,6 +48,7 @@ from ....plugins.hid import BaseHid
|
|||||||
from ....validators import raise_error
|
from ....validators import raise_error
|
||||||
from ....validators.basic import valid_bool
|
from ....validators.basic import valid_bool
|
||||||
from ....validators.basic import valid_int_f0
|
from ....validators.basic import valid_int_f0
|
||||||
|
from ....validators.basic import valid_string_list
|
||||||
from ....validators.os import valid_printable_filename
|
from ....validators.os import valid_printable_filename
|
||||||
from ....validators.hid import valid_hid_keyboard_output
|
from ....validators.hid import valid_hid_keyboard_output
|
||||||
from ....validators.hid import valid_hid_mouse_output
|
from ....validators.hid import valid_hid_mouse_output
|
||||||
@ -256,6 +258,19 @@ class HidApi:
|
|||||||
|
|
||||||
# =====
|
# =====
|
||||||
|
|
||||||
|
@exposed_http("POST", "/hid/events/send_shortcut")
|
||||||
|
async def __events_send_shortcut_handler(self, req: Request) -> Response:
|
||||||
|
shortcut = valid_string_list(req.query.get("keys"), subval=valid_hid_key)
|
||||||
|
if shortcut:
|
||||||
|
press = [WEB_TO_EVDEV[key] for key in shortcut]
|
||||||
|
release = list(reversed(press))
|
||||||
|
seq = [
|
||||||
|
*zip(press, itertools.repeat(True)),
|
||||||
|
*zip(release, itertools.repeat(False)),
|
||||||
|
]
|
||||||
|
await self.__hid.send_key_events(seq, no_ignore_keys=True, slow=True)
|
||||||
|
return make_json_response()
|
||||||
|
|
||||||
@exposed_http("POST", "/hid/events/send_key")
|
@exposed_http("POST", "/hid/events/send_key")
|
||||||
async def __events_send_key_handler(self, req: Request) -> Response:
|
async def __events_send_key_handler(self, req: Request) -> Response:
|
||||||
key = WEB_TO_EVDEV[valid_hid_key(req.query.get("key"))]
|
key = WEB_TO_EVDEV[valid_hid_key(req.query.get("key"))]
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user