Skip to content

Commit 11160d2

Browse files
committed
fix nonascii characters and dvorak and german layouts
1 parent 57b2edf commit 11160d2

File tree

3 files changed

+26
-20
lines changed

3 files changed

+26
-20
lines changed

libraries/keyboard_layout.py

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ def keycodes(self, char):
9292

9393
return codes
9494

95-
def _above128charval_to_keycode(self, char_val):
95+
def _above128char_to_keycode(self, char):
9696
"""Return keycode for above 128 ascii codes.
9797
9898
Since the values are sparse, this may be more space efficient than bloating the table above
@@ -101,12 +101,15 @@ def _above128charval_to_keycode(self, char_val):
101101
:param char_val: ascii char value
102102
:return: keycode, with modifiers if needed
103103
"""
104-
if char_val in self.HIGHER_ASCII:
105-
return self.HIGHER_ASCII[char_val]
106-
if ord(char_val) in self.HIGHER_ASCII:
107-
return self.HIGHER_ASCII[char_val]
104+
if char in self.HIGHER_ASCII:
105+
return self.HIGHER_ASCII[char]
106+
if ord(char) in self.HIGHER_ASCII:
107+
return self.HIGHER_ASCII[ord(char)]
108108

109-
raise ValueError("Unsupported non-ASCII character \\x{}.".format(ord(char_val)))
109+
raise ValueError(
110+
"Unsupported non-ASCII character {} \\x{}."
111+
.format(str(char), ord(char))
112+
)
110113

111114
def _char_to_keycode(self, char):
112115
"""Return the HID keycode for the given ASCII character, with the SHIFT_FLAG possibly set.
@@ -115,9 +118,12 @@ def _char_to_keycode(self, char):
115118
You must clear this bit before passing the keycode in a USB report.
116119
"""
117120
char_val = ord(char)
118-
if char_val > 128:
119-
return self._above128charval_to_keycode(char)
121+
if char_val > len(self.ASCII_TO_KEYCODE):
122+
return self._above128char_to_keycode(char)
120123
keycode = self.ASCII_TO_KEYCODE[char_val]
121124
if keycode == 0:
122-
raise ValueError("No keycode available for character.")
125+
raise ValueError(
126+
"No keycode available for character {} \\x{}."
127+
.format(str(char), char_val)
128+
)
123129
return keycode

libraries/keyboard_layout_us_dvo.py

100644100755
File mode changed.

libraries/keyboard_layout_win_de_de.py

100644100755
Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ class KeyboardLayoutWinDeDe(KeyboardLayout):
9090
b"\xa7" # =
9191
b"\xe4" # >
9292
b"\xad" # ?
93-
b"\x14", # @
93+
b"\x14" # @
9494
b"\x84" # A
9595
b"\x85" # B
9696
b"\x86" # C
@@ -117,9 +117,9 @@ class KeyboardLayoutWinDeDe(KeyboardLayout):
117117
b"\x9b" # X
118118
b"\x9d" # Y
119119
b"\x9c" # Z
120-
b"\x25", # [
121-
b"\x2d", # bslash \
122-
b"\x26", # ]
120+
b"\x25" # [
121+
b"\x2d" # bslash \
122+
b"\x26" # ]
123123
b"\x35" # ^
124124
b"\xb8" # _
125125
b"\xae" # `
@@ -149,10 +149,10 @@ class KeyboardLayoutWinDeDe(KeyboardLayout):
149149
b"\x1b" # x
150150
b"\x1d" # y
151151
b"\x1c" # z
152-
b"\x24", # {
153-
b"\x64", # |
154-
b"\x27", # }
155-
b"\x30", # ~
152+
b"\x24" # {
153+
b"\x64" # |
154+
b"\x27" # }
155+
b"\x30" # ~
156156
b"\x4c" # DEL
157157
b"\x00" # [NOT printable] in some docs shown as € symbol, but not so in python
158158
b"\x00" # [not printable]
@@ -204,10 +204,10 @@ class KeyboardLayoutWinDeDe(KeyboardLayout):
204204
b"\x00" # ¯
205205
b"\xb5" # °
206206
b"\x00" # ±
207-
b"\x1f", # ²
208-
b"\x20", # ³
207+
b"\x1f" # ²
208+
b"\x20" # ³
209209
b"\x2e" # ´
210-
b"\x10", # µ
210+
b"\x10" # µ
211211
b"\x00" # ¶
212212
b"\x00" # ·
213213
b"\x00" # ¸

0 commit comments

Comments
 (0)