Skip to content

Commit 14a2203

Browse files
committed
format and english in alt_codes
1 parent 11c6965 commit 14a2203

File tree

1 file changed

+12
-21
lines changed

1 file changed

+12
-21
lines changed

libraries/helpers/alt_codes.py

Lines changed: 12 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,10 @@
77

88
from adafruit_hid.keycode import Keycode
99

10+
1011
class Altcode(Keycode):
1112
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)
1414

1515
def __init__(self, keyboard, layout):
1616
self.keyboard = keyboard
@@ -20,29 +20,26 @@ def _special_char(self, char_value):
2020
if char_value == 0x0A or char_value == 0x0D:
2121
self.keyboard.send(Keycode.ENTER)
2222
elif char_value == 0x09:
23-
self.keyboard.send(Keycode.TAB)
23+
self.keyboard.send(Keycode.TAB)
2424
else:
2525
raise ValueError("Value of char is unknown:", char_value)
26-
27-
26+
2827
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
3230
indice = self.unicodeChar.find(char)
3331
if indice != -1:
3432
char_val = self.asciiexValue[indice]
3533
else:
3634
char_val = ord(char)
3735
return char_val
3836

39-
4037
def _num_to_keypad(self, string):
4138
for char in string:
4239
if char.isdigit():
4340
num = int(char)
41+
# don't use send because it releases all
4442
if num > 0:
45-
# Ne pas utiliser la fonction send qui effectue un releaseAll
4643
self.keyboard.press(self.KEYPAD_ONE + num - 1)
4744
self.keyboard.release(self.KEYPAD_ONE + num - 1)
4845
elif num == 0:
@@ -52,50 +49,44 @@ def _num_to_keypad(self, string):
5249
raise ValueError("Char is not a digit:", char)
5350
break
5451

55-
5652
def _win_alt_code_CP1252(self, asciiex_string):
5753
len_asciiex = len(asciiex_string)
5854
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
6157
self.keyboard.press(self.KEYPAD_ZERO)
6258
self.keyboard.release(self.KEYPAD_ZERO)
6359
self._num_to_keypad(asciiex_string)
6460
self.keyboard.release_all()
6561

66-
6762
def _win_alt_unicode_point(self, unicode_string):
6863
self.keyboard.press(self.ALT)
6964
self._num_to_keypad(unicode_string)
7065
self.keyboard.release_all()
7166

72-
7367
def windows(self, string):
7468
for char in string:
7569
char_val = self._get_value_of_char(char)
7670
if char_val < 32:
77-
# pour les valeurs TAB et \n
71+
# for TAB and \n
7872
self._special_char(char_val)
7973
elif char_val < 256:
8074
self._win_alt_code_CP1252(str(char_val))
8175
else:
8276
self._win_alt_unicode_point(str(char_val))
8377

84-
8578
def _linux_alt_unicode_point(self, unicode_stringHex):
8679
self.keyboard.send(self.CONTROL, self.SHIFT, self.U)
8780
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
9082
self.keyboard.send(self.layout.keycodes(char)[-1])
9183
self.keyboard.send(self.ENTER)
9284

93-
9485
def linux(self, string):
9586
for char in string:
9687
char_val = ord(char)
9788
if char_val < 32:
98-
# pour les valeurs TAB et \n
89+
# for TAB and \n
9990
self._special_char(char_val)
10091
else:
10192
self._linux_alt_unicode_point(hex(char_val))

0 commit comments

Comments
 (0)