forked from selkies-project/selkies-gstreamer
-
Notifications
You must be signed in to change notification settings - Fork 0
/
xorg.py
34 lines (26 loc) · 1.07 KB
/
xorg.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
import ctypes
import logging
logger = logging.getLogger("xorg")
logger.setLevel(logging.INFO)
class Xorg:
def __init__(self, display_name):
# Load the shared library
self.libxorg = ctypes.CDLL('/usr/local/lib/selkies-xorg-iface/xorg.so')
# Define the argument and return types for the functions you need
self.libxorg.XDisplayOpen.argtypes = [ctypes.c_char_p]
self.libxorg.XDisplayOpen.restype = ctypes.c_int
self.libxorg.XKey.argtypes = [ctypes.c_ulong, ctypes.c_int]
self.libxorg.XKey.restype = None
success = self.libxorg.XDisplayOpen(str.encode(display_name))
if success != 0:
raise RuntimeError("Failed to open display")
def key_up(self, keysym):
try:
self.libxorg.XKey(keysym, 0)
except Exception as e:
logger.warning("Failed to send key up event: %s" % e)
def key_down(self, keysym):
try:
self.libxorg.XKey(keysym, 1)
except Exception as e:
logger.warning("Failed to send key down event: %s" % e)