Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
R
rustdesk
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
李朝发
rustdesk
Commits
1833b8c2
Commit
1833b8c2
authored
Jun 23, 2022
by
Asura
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix(pynput): Convert keysym to keycode according to the system input source
parent
ef1f34ce
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
12 additions
and
46 deletions
+12
-46
pynput_service.py
pynput_service.py
+12
-46
No files found.
pynput_service.py
View file @
1833b8c2
from
pynput.keyboard
import
Key
,
Controller
from
pynput.keyboard._xorg
import
KeyCode
from
pynput._util.xorg
import
display_manager
import
Xlib
import
os
import
sys
import
socket
from
Xlib.ext.xtest
import
fake_input
from
Xlib
import
X
KeyCode
.
_from_symbol
(
"
\0
"
)
# test
class
MyController
(
Controller
):
def
_handle
(
self
,
key
,
is_press
):
"""Resolves a key identifier and sends a keyboard event.
:param event: The *X* keyboard event.
:param int keysym: The keysym to handle.
"""
event
=
Xlib
.
display
.
event
.
KeyPress
if
is_press
\
else
Xlib
.
display
.
event
.
KeyRelease
keysym
=
self
.
_keysym
(
key
)
# Make sure to verify that the key was resolved
if
keysym
is
None
:
raise
self
.
InvalidKeyException
(
key
)
# If the key has a virtual key code, use that immediately with
# fake_input; fake input,being an X server extension, has access to
# more internal state that we do
if
key
.
vk
is
not
None
:
with
display_manager
(
self
.
_display
)
as
dm
:
Xlib
.
ext
.
xtest
.
fake_input
(
dm
,
Xlib
.
X
.
KeyPress
if
is_press
else
Xlib
.
X
.
KeyRelease
,
dm
.
keysym_to_keycode
(
key
.
vk
))
event
=
X
.
KeyPress
if
is_press
\
else
X
.
KeyRelease
# Otherwise use XSendEvent; we need to use this in the general case to
# work around problems with keyboard layouts
else
:
try
:
keycode
,
shift_state
=
self
.
keyboard_mapping
[
keysym
]
with
self
.
modifiers
as
modifiers
:
alt_gr
=
Key
.
alt_gr
in
modifiers
if
alt_gr
:
self
.
_send_key
(
event
,
keycode
,
shift_state
)
else
:
with
display_manager
(
self
.
_display
)
as
dm
:
Xlib
.
ext
.
xtest
.
fake_input
(
dm
,
Xlib
.
X
.
KeyPress
if
is_press
else
Xlib
.
X
.
KeyRelease
,
keycode
)
keysym
=
self
.
_keysym
(
key
)
# Get keycode according to system language
keycode
=
self
.
_display
.
keysym_to_keycode
(
keysym
)
print
(
keycode
)
except
KeyError
:
with
self
.
_borrow_lock
:
keycode
,
index
,
count
=
self
.
_borrows
[
keysym
]
self
.
_send_key
(
event
,
keycode
,
index_to_shift
(
self
.
_display
,
index
))
count
+=
1
if
is_press
else
-
1
self
.
_borrows
[
keysym
]
=
(
keycode
,
index
,
count
)
fake_input
(
self
.
_display
,
event
,
keycode
)
self
.
_display
.
sync
()
# Notify any running listeners
self
.
_emit
(
'_on_fake_event'
,
key
,
is_press
)
keyboard
=
MyController
()
...
...
@@ -77,7 +44,7 @@ server = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM)
server
.
bind
(
server_address
)
server
.
listen
(
1
)
clientsocket
,
address
=
server
.
accept
()
os
.
system
(
'chmod a+rw
%
s'
%
server_address
)
os
.
system
(
'chmod a+rw
%
s'
%
server_address
)
print
(
"Got pynput connection"
)
...
...
@@ -121,4 +88,3 @@ def loop():
loop
()
clientsocket
.
close
()
server
.
close
()
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment