Replaced fake_input with display_manager's send_event
This commit is contained in:
parent
8aeacf77b3
commit
c842642c02
@ -6,6 +6,7 @@ import sys
|
|||||||
import socket
|
import socket
|
||||||
from Xlib.ext.xtest import fake_input
|
from Xlib.ext.xtest import fake_input
|
||||||
from Xlib import X
|
from Xlib import X
|
||||||
|
import Xlib
|
||||||
|
|
||||||
KeyCode._from_symbol("\0") # test
|
KeyCode._from_symbol("\0") # test
|
||||||
|
|
||||||
@ -16,15 +17,31 @@ class MyController(Controller):
|
|||||||
:param event: The *X* keyboard event.
|
:param event: The *X* keyboard event.
|
||||||
:param int keysym: The keysym to handle.
|
:param int keysym: The keysym to handle.
|
||||||
"""
|
"""
|
||||||
event = X.KeyPress if is_press \
|
|
||||||
else X.KeyRelease
|
|
||||||
|
|
||||||
keysym = self._keysym(key)
|
event = Xlib.display.event.KeyPress if is_press \
|
||||||
# Get keycode according to system language
|
else Xlib.display.event.KeyRelease
|
||||||
keycode = self._display.keysym_to_keycode(keysym)
|
|
||||||
|
origin_keysym = self._keysym(key)
|
||||||
|
keycode = self._display.keysym_to_keycode(origin_keysym)
|
||||||
|
|
||||||
|
with display_manager(self._display) as dm, self.modifiers as modifiers:
|
||||||
|
# Under certain cimcumstances, such as when running under Xephyr,
|
||||||
|
# the value returned by dm.get_input_focus is an int
|
||||||
|
window = dm.get_input_focus().focus
|
||||||
|
send_event = getattr(
|
||||||
|
window,
|
||||||
|
'send_event',
|
||||||
|
lambda event: dm.send_event(window, event))
|
||||||
|
send_event(event(
|
||||||
|
detail=keycode,
|
||||||
|
state=self._shift_mask(modifiers),
|
||||||
|
time=0,
|
||||||
|
root=dm.screen().root,
|
||||||
|
window=window,
|
||||||
|
same_screen=0,
|
||||||
|
child=Xlib.X.NONE,
|
||||||
|
root_x=0, root_y=0, event_x=0, event_y=0))
|
||||||
|
|
||||||
fake_input(self._display, event, keycode)
|
|
||||||
self._display.sync()
|
|
||||||
|
|
||||||
|
|
||||||
keyboard = MyController()
|
keyboard = MyController()
|
||||||
|
Loading…
Reference in New Issue
Block a user