7
7
8
8
from adafruit_hid .keycode import Keycode
9
9
10
+
10
11
class Altcode (Keycode ):
11
12
unicodeChar = "€‚ƒ„…†‡ˆ‰Š‹ŒŽ‘’“”•–—˜™š›œžŸ"
12
- asciiexValue = (128 , 130 , 131 , 132 , 133 , 134 , 135 , 136 , 137 , 138 , 139 , 140 , 142 , 145 , 146 , 147 , 148 , 149 , 150 ,
13
- 151 , 152 , 153 , 154 , 155 , 156 , 158 , 159 )
13
+ asciiexValue = (128 , 130 , 131 , 132 , 133 , 134 , 135 , 136 , 137 , 138 , 139 , 140 , 142 , 145 , 146 , 147 , 148 , 149 , 150 , 151 , 152 , 153 , 154 , 155 , 156 , 158 , 159 )
14
14
15
15
def __init__ (self , keyboard , layout ):
16
16
self .keyboard = keyboard
@@ -20,29 +20,26 @@ def _special_char(self, char_value):
20
20
if char_value == 0x0A or char_value == 0x0D :
21
21
self .keyboard .send (Keycode .ENTER )
22
22
elif char_value == 0x09 :
23
- self .keyboard .send (Keycode .TAB )
23
+ self .keyboard .send (Keycode .TAB )
24
24
else :
25
25
raise ValueError ("Value of char is unknown:" , char_value )
26
-
27
-
26
+
28
27
def _get_value_of_char (self , char ):
29
- # Si le caractère fait partie de la table ASCII étendue
30
- # renvoie la valeur ASCII étendue du caractère
31
- # sinon renvoie la valeur Unicode
28
+ # if the character is in the extended ascii table,
29
+ # return the ASCII value else return the unicode value
32
30
indice = self .unicodeChar .find (char )
33
31
if indice != - 1 :
34
32
char_val = self .asciiexValue [indice ]
35
33
else :
36
34
char_val = ord (char )
37
35
return char_val
38
36
39
-
40
37
def _num_to_keypad (self , string ):
41
38
for char in string :
42
39
if char .isdigit ():
43
40
num = int (char )
41
+ # don't use send because it releases all
44
42
if num > 0 :
45
- # Ne pas utiliser la fonction send qui effectue un releaseAll
46
43
self .keyboard .press (self .KEYPAD_ONE + num - 1 )
47
44
self .keyboard .release (self .KEYPAD_ONE + num - 1 )
48
45
elif num == 0 :
@@ -52,50 +49,44 @@ def _num_to_keypad(self, string):
52
49
raise ValueError ("Char is not a digit:" , char )
53
50
break
54
51
55
-
56
52
def _win_alt_code_CP1252 (self , asciiex_string ):
57
53
len_asciiex = len (asciiex_string )
58
54
self .keyboard .press (self .ALT )
59
- for x in range (4 - len_asciiex ):
60
- # Ne pas utiliser la fonction send qui effectue un releaseAll
55
+ for x in range (4 - len_asciiex ):
56
+ # don't use send because it releases all
61
57
self .keyboard .press (self .KEYPAD_ZERO )
62
58
self .keyboard .release (self .KEYPAD_ZERO )
63
59
self ._num_to_keypad (asciiex_string )
64
60
self .keyboard .release_all ()
65
61
66
-
67
62
def _win_alt_unicode_point (self , unicode_string ):
68
63
self .keyboard .press (self .ALT )
69
64
self ._num_to_keypad (unicode_string )
70
65
self .keyboard .release_all ()
71
66
72
-
73
67
def windows (self , string ):
74
68
for char in string :
75
69
char_val = self ._get_value_of_char (char )
76
70
if char_val < 32 :
77
- # pour les valeurs TAB et \n
71
+ # for TAB and \n
78
72
self ._special_char (char_val )
79
73
elif char_val < 256 :
80
74
self ._win_alt_code_CP1252 (str (char_val ))
81
75
else :
82
76
self ._win_alt_unicode_point (str (char_val ))
83
77
84
-
85
78
def _linux_alt_unicode_point (self , unicode_stringHex ):
86
79
self .keyboard .send (self .CONTROL , self .SHIFT , self .U )
87
80
for char in unicode_stringHex [2 :]:
88
- # on n'envoie pas le shift ou le altgr ici!
89
- # seul la position de la touche est nécessaire!
81
+ # don't send shift or altgr here, only the key pos is required
90
82
self .keyboard .send (self .layout .keycodes (char )[- 1 ])
91
83
self .keyboard .send (self .ENTER )
92
84
93
-
94
85
def linux (self , string ):
95
86
for char in string :
96
87
char_val = ord (char )
97
88
if char_val < 32 :
98
- # pour les valeurs TAB et \n
89
+ # for TAB and \n
99
90
self ._special_char (char_val )
100
91
else :
101
92
self ._linux_alt_unicode_point (hex (char_val ))
0 commit comments