1
- import os
2
- import subprocess as sp
3
1
from subprocess import run
4
2
5
- from ..abstractionhelper import get_event_code , is_installed
6
- from ..action import __get_codepoints as get_codepoints
3
+ from ..abstractionhelper import is_installed
4
+ from ..action import __get_codepoints as get_codepoints , __get_event_code as get_event_code
7
5
from .typer import Typer
8
6
9
7
class YdotoolTyper (Typer ):
10
- def __init__ (self ):
11
- super ().__init__ ()
12
-
13
- self .socket = "/run/user/1000/.ydotool_socket"
14
- if "YDOTOOL_SOCKET" in os .environ :
15
- self .socket = os .environ ["YDOTOOL_SOCKET" ]
16
-
17
8
@staticmethod
18
9
def name ():
19
10
return "ydotool"
20
11
21
12
@staticmethod
22
13
def supported ():
23
- try :
24
- return is_installed ("ydotool" )
25
- except sp .CalledProcessError :
26
- return False
14
+ return is_installed ("ydotool" )
27
15
28
16
def get_active_window (self ):
29
17
return "not possible with ydotool"
@@ -37,27 +25,25 @@ def type_characters(self, characters: str, active_window: str) -> None:
37
25
unicode_code_point = get_codepoints (character )
38
26
39
27
# Get keypresses for Ctrl, Shift, U, and the unicode code point
40
- Ctrl = get_event_code ("LeftCtrl" )
41
- Shift = get_event_code ("LeftShift" )
42
- U = get_event_code ("U" )
43
- Ctrl_release = get_event_code ("LeftCtrl" , False )
44
- Shift_release = get_event_code ("LeftShift" , False )
45
- U_release = get_event_code ("U" , False )
28
+ Ctrl = get_event_code ("LeftCtrl" ) + ":1"
29
+ Shift = get_event_code ("LeftShift" ) + ":1"
30
+ U_press = get_event_code ("U" ) + ":1"
31
+ Ctrl_release = get_event_code ("LeftCtrl" ) + ":0"
32
+ Shift_release = get_event_code ("LeftShift" ) + ":0"
33
+ U_release = get_event_code ("U" ) + ":0"
46
34
points = []
47
35
48
36
for point in unicode_code_point :
49
- points .append (get_event_code (point ))
50
- points .append (get_event_code (point , False ) )
37
+ points .append (get_event_code (point ) + ":1" )
38
+ points .append (get_event_code (point ) + ":0" )
51
39
52
40
# Send the event codes to ydotool
53
- the_array = ["ydotool" , "key" , "--key-delay" , "1" , Ctrl , Shift , U , U_release ] + points + [Shift_release , Ctrl_release ]
54
- run (the_array , env = os .environ .copy ().update ({"YDOTOOL_SOCKET" : self .socket }))
41
+ run (["ydotool" , "key" , Ctrl , Shift , U_press , U_release ] + points + [Shift_release , Ctrl_release ])
55
42
56
43
def insert_from_clipboard (self , active_window : str ) -> None :
57
- Shift = get_event_code ("LeftShift" )
58
- Shift_release = get_event_code ("LeftShift" , False )
59
- Insert = get_event_code ("Insert" )
60
- Insert_release = get_event_code ("Insert" , False )
44
+ Shift = get_event_code ("LeftShift" ) + ":1"
45
+ Shift_release = get_event_code ("LeftShift" ) + ":0"
46
+ Insert = get_event_code ("Insert" ) + ":1"
47
+ Insert_release = get_event_code ("Insert" ) + ":0"
61
48
62
- run (["ydotool" , "key" , Shift , Insert , Insert_release , Shift_release ],
63
- env = os .environ .copy ().update ({"YDOTOOL_SOCKET" : self .socket }))
49
+ run (["ydotool" , "key" , Shift , Insert , Insert_release , Shift_release ])
0 commit comments