3030
3131from .keycode import Keycode
3232
33+
3334class KeyboardLayoutUS :
3435 """Map ASCII characters to appropriate keypresses on a standard US PC keyboard.
3536
@@ -51,134 +52,134 @@ class KeyboardLayoutUS:
5152 # \x00 entries have no keyboard key and so won't be sent.
5253 SHIFT_FLAG = 0x80
5354 ASCII_TO_KEYCODE = (
54- b' \x00 ' # NUL
55- b' \x00 ' # SOH
56- b' \x00 ' # STX
57- b' \x00 ' # ETX
58- b' \x00 ' # EOT
59- b' \x00 ' # ENQ
60- b' \x00 ' # ACK
61- b' \x00 ' # BEL \a
62- b' \x2a ' # BS BACKSPACE \b (called DELETE in the usb.org document)
63- b' \x2b ' # TAB \t
64- b' \x28 ' # LF \n (called Return or ENTER in the usb.org document)
65- b' \x00 ' # VT \v
66- b' \x00 ' # FF \f
67- b' \x00 ' # CR \r
68- b' \x00 ' # SO
69- b' \x00 ' # SI
70- b' \x00 ' # DLE
71- b' \x00 ' # DC1
72- b' \x00 ' # DC2
73- b' \x00 ' # DC3
74- b' \x00 ' # DC4
75- b' \x00 ' # NAK
76- b' \x00 ' # SYN
77- b' \x00 ' # ETB
78- b' \x00 ' # CAN
79- b' \x00 ' # EM
80- b' \x00 ' # SUB
81- b' \x29 ' # ESC
82- b' \x00 ' # FS
83- b' \x00 ' # GS
84- b' \x00 ' # RS
85- b' \x00 ' # US
86- b' \x2c ' # SPACE
87- b' \x9e ' # ! x1e|SHIFT_FLAG (shift 1)
88- b' \xb4 ' # " x34|SHIFT_FLAG (shift ')
89- b' \xa0 ' # # x20|SHIFT_FLAG (shift 3)
90- b' \xa1 ' # $ x21|SHIFT_FLAG (shift 4)
91- b' \xa2 ' # % x22|SHIFT_FLAG (shift 5)
92- b' \xa4 ' # & x24|SHIFT_FLAG (shift 7)
93- b' \x34 ' # '
94- b' \xa6 ' # ( x26|SHIFT_FLAG (shift 9)
95- b' \xa7 ' # ) x27|SHIFT_FLAG (shift 0)
96- b' \xa5 ' # * x25|SHIFT_FLAG (shift 8)
97- b' \xae ' # + x2e|SHIFT_FLAG (shift =)
98- b' \x36 ' # ,
99- b' \x2d ' # -
100- b' \x37 ' # .
101- b' \x38 ' # /
102- b' \x27 ' # 0
103- b' \x1e ' # 1
104- b' \x1f ' # 2
105- b' \x20 ' # 3
106- b' \x21 ' # 4
107- b' \x22 ' # 5
108- b' \x23 ' # 6
109- b' \x24 ' # 7
110- b' \x25 ' # 8
111- b' \x26 ' # 9
112- b' \xb3 ' # : x33|SHIFT_FLAG (shift ;)
113- b' \x33 ' # ;
114- b' \xb6 ' # < x36|SHIFT_FLAG (shift ,)
115- b' \x2e ' # =
116- b' \xb7 ' # > x37|SHIFT_FLAG (shift .)
117- b' \xb8 ' # ? x38|SHIFT_FLAG (shift /)
118- b' \x9f ' # @ x1f|SHIFT_FLAG (shift 2)
119- b' \x84 ' # A x04|SHIFT_FLAG (shift a)
120- b' \x85 ' # B x05|SHIFT_FLAG (etc.)
121- b' \x86 ' # C x06|SHIFT_FLAG
122- b' \x87 ' # D x07|SHIFT_FLAG
123- b' \x88 ' # E x08|SHIFT_FLAG
124- b' \x89 ' # F x09|SHIFT_FLAG
125- b' \x8a ' # G x0a|SHIFT_FLAG
126- b' \x8b ' # H x0b|SHIFT_FLAG
127- b' \x8c ' # I x0c|SHIFT_FLAG
128- b' \x8d ' # J x0d|SHIFT_FLAG
129- b' \x8e ' # K x0e|SHIFT_FLAG
130- b' \x8f ' # L x0f|SHIFT_FLAG
131- b' \x90 ' # M x10|SHIFT_FLAG
132- b' \x91 ' # N x11|SHIFT_FLAG
133- b' \x92 ' # O x12|SHIFT_FLAG
134- b' \x93 ' # P x13|SHIFT_FLAG
135- b' \x94 ' # Q x14|SHIFT_FLAG
136- b' \x95 ' # R x15|SHIFT_FLAG
137- b' \x96 ' # S x16|SHIFT_FLAG
138- b' \x97 ' # T x17|SHIFT_FLAG
139- b' \x98 ' # U x18|SHIFT_FLAG
140- b' \x99 ' # V x19|SHIFT_FLAG
141- b' \x9a ' # W x1a|SHIFT_FLAG
142- b' \x9b ' # X x1b|SHIFT_FLAG
143- b' \x9c ' # Y x1c|SHIFT_FLAG
144- b' \x9d ' # Z x1d|SHIFT_FLAG
145- b' \x2f ' # [
146- b' \x31 ' # \ backslash
147- b' \x30 ' # ]
148- b' \xa3 ' # ^ x23|SHIFT_FLAG (shift 6)
149- b' \xad ' # _ x2d|SHIFT_FLAG (shift -)
150- b' \x35 ' # `
151- b' \x04 ' # a
152- b' \x05 ' # b
153- b' \x06 ' # c
154- b' \x07 ' # d
155- b' \x08 ' # e
156- b' \x09 ' # f
157- b' \x0a ' # g
158- b' \x0b ' # h
159- b' \x0c ' # i
160- b' \x0d ' # j
161- b' \x0e ' # k
162- b' \x0f ' # l
163- b' \x10 ' # m
164- b' \x11 ' # n
165- b' \x12 ' # o
166- b' \x13 ' # p
167- b' \x14 ' # q
168- b' \x15 ' # r
169- b' \x16 ' # s
170- b' \x17 ' # t
171- b' \x18 ' # u
172- b' \x19 ' # v
173- b' \x1a ' # w
174- b' \x1b ' # x
175- b' \x1c ' # y
176- b' \x1d ' # z
177- b' \xaf ' # { x2f|SHIFT_FLAG (shift [)
178- b' \xb1 ' # | x31|SHIFT_FLAG (shift \)
179- b' \xb0 ' # } x30|SHIFT_FLAG (shift ])
180- b' \xb5 ' # ~ x35|SHIFT_FLAG (shift `)
181- b' \x4c ' # DEL DELETE (called Forward Delete in usb.org document)
55+ b" \x00 " # NUL
56+ b" \x00 " # SOH
57+ b" \x00 " # STX
58+ b" \x00 " # ETX
59+ b" \x00 " # EOT
60+ b" \x00 " # ENQ
61+ b" \x00 " # ACK
62+ b" \x00 " # BEL \a
63+ b" \x2a " # BS BACKSPACE \b (called DELETE in the usb.org document)
64+ b" \x2b " # TAB \t
65+ b" \x28 " # LF \n (called Return or ENTER in the usb.org document)
66+ b" \x00 " # VT \v
67+ b" \x00 " # FF \f
68+ b" \x00 " # CR \r
69+ b" \x00 " # SO
70+ b" \x00 " # SI
71+ b" \x00 " # DLE
72+ b" \x00 " # DC1
73+ b" \x00 " # DC2
74+ b" \x00 " # DC3
75+ b" \x00 " # DC4
76+ b" \x00 " # NAK
77+ b" \x00 " # SYN
78+ b" \x00 " # ETB
79+ b" \x00 " # CAN
80+ b" \x00 " # EM
81+ b" \x00 " # SUB
82+ b" \x29 " # ESC
83+ b" \x00 " # FS
84+ b" \x00 " # GS
85+ b" \x00 " # RS
86+ b" \x00 " # US
87+ b" \x2c " # SPACE
88+ b" \x9e " # ! x1e|SHIFT_FLAG (shift 1)
89+ b" \xb4 " # " x34|SHIFT_FLAG (shift ')
90+ b" \xa0 " # # x20|SHIFT_FLAG (shift 3)
91+ b" \xa1 " # $ x21|SHIFT_FLAG (shift 4)
92+ b" \xa2 " # % x22|SHIFT_FLAG (shift 5)
93+ b" \xa4 " # & x24|SHIFT_FLAG (shift 7)
94+ b" \x34 " # '
95+ b" \xa6 " # ( x26|SHIFT_FLAG (shift 9)
96+ b" \xa7 " # ) x27|SHIFT_FLAG (shift 0)
97+ b" \xa5 " # * x25|SHIFT_FLAG (shift 8)
98+ b" \xae " # + x2e|SHIFT_FLAG (shift =)
99+ b" \x36 " # ,
100+ b" \x2d " # -
101+ b" \x37 " # .
102+ b" \x38 " # /
103+ b" \x27 " # 0
104+ b" \x1e " # 1
105+ b" \x1f " # 2
106+ b" \x20 " # 3
107+ b" \x21 " # 4
108+ b" \x22 " # 5
109+ b" \x23 " # 6
110+ b" \x24 " # 7
111+ b" \x25 " # 8
112+ b" \x26 " # 9
113+ b" \xb3 " # : x33|SHIFT_FLAG (shift ;)
114+ b" \x33 " # ;
115+ b" \xb6 " # < x36|SHIFT_FLAG (shift ,)
116+ b" \x2e " # =
117+ b" \xb7 " # > x37|SHIFT_FLAG (shift .)
118+ b" \xb8 " # ? x38|SHIFT_FLAG (shift /)
119+ b" \x9f " # @ x1f|SHIFT_FLAG (shift 2)
120+ b" \x84 " # A x04|SHIFT_FLAG (shift a)
121+ b" \x85 " # B x05|SHIFT_FLAG (etc.)
122+ b" \x86 " # C x06|SHIFT_FLAG
123+ b" \x87 " # D x07|SHIFT_FLAG
124+ b" \x88 " # E x08|SHIFT_FLAG
125+ b" \x89 " # F x09|SHIFT_FLAG
126+ b" \x8a " # G x0a|SHIFT_FLAG
127+ b" \x8b " # H x0b|SHIFT_FLAG
128+ b" \x8c " # I x0c|SHIFT_FLAG
129+ b" \x8d " # J x0d|SHIFT_FLAG
130+ b" \x8e " # K x0e|SHIFT_FLAG
131+ b" \x8f " # L x0f|SHIFT_FLAG
132+ b" \x90 " # M x10|SHIFT_FLAG
133+ b" \x91 " # N x11|SHIFT_FLAG
134+ b" \x92 " # O x12|SHIFT_FLAG
135+ b" \x93 " # P x13|SHIFT_FLAG
136+ b" \x94 " # Q x14|SHIFT_FLAG
137+ b" \x95 " # R x15|SHIFT_FLAG
138+ b" \x96 " # S x16|SHIFT_FLAG
139+ b" \x97 " # T x17|SHIFT_FLAG
140+ b" \x98 " # U x18|SHIFT_FLAG
141+ b" \x99 " # V x19|SHIFT_FLAG
142+ b" \x9a " # W x1a|SHIFT_FLAG
143+ b" \x9b " # X x1b|SHIFT_FLAG
144+ b" \x9c " # Y x1c|SHIFT_FLAG
145+ b" \x9d " # Z x1d|SHIFT_FLAG
146+ b" \x2f " # [
147+ b" \x31 " # \ backslash
148+ b" \x30 " # ]
149+ b" \xa3 " # ^ x23|SHIFT_FLAG (shift 6)
150+ b" \xad " # _ x2d|SHIFT_FLAG (shift -)
151+ b" \x35 " # `
152+ b" \x04 " # a
153+ b" \x05 " # b
154+ b" \x06 " # c
155+ b" \x07 " # d
156+ b" \x08 " # e
157+ b" \x09 " # f
158+ b" \x0a " # g
159+ b" \x0b " # h
160+ b" \x0c " # i
161+ b" \x0d " # j
162+ b" \x0e " # k
163+ b" \x0f " # l
164+ b" \x10 " # m
165+ b" \x11 " # n
166+ b" \x12 " # o
167+ b" \x13 " # p
168+ b" \x14 " # q
169+ b" \x15 " # r
170+ b" \x16 " # s
171+ b" \x17 " # t
172+ b" \x18 " # u
173+ b" \x19 " # v
174+ b" \x1a " # w
175+ b" \x1b " # x
176+ b" \x1c " # y
177+ b" \x1d " # z
178+ b" \xaf " # { x2f|SHIFT_FLAG (shift [)
179+ b" \xb1 " # | x31|SHIFT_FLAG (shift \)
180+ b" \xb0 " # } x30|SHIFT_FLAG (shift ])
181+ b" \xb5 " # ~ x35|SHIFT_FLAG (shift `)
182+ b" \x4c " # DEL DELETE (called Forward Delete in usb.org document)
182183 )
183184
184185 def __init__ (self , keyboard ):
0 commit comments