@@ -122,7 +122,26 @@ def _init_sdl_video() -> None:
122
122
123
123
124
124
class Modifier (enum .IntFlag ):
125
- """Keyboard modifier flags.
125
+ """Keyboard modifier flags, a bitfield of held modifier keys.
126
+
127
+ Use `bitwise and` to check if a modifier key is held.
128
+
129
+ The following example shows some common ways of checking modifiers.
130
+ All non-zero return values are considered true.
131
+
132
+ Example::
133
+
134
+ >>> mod = tcod.event.Modifier(4098)
135
+ >>> mod
136
+ <Modifier.NUM|RSHIFT: 4098>
137
+ >>> mod & tcod.event.Modifier.SHIFT # Check if any shift key is held.
138
+ <Modifier.RSHIFT: 2>
139
+ >>> mod & tcod.event.Modifier.LSHIFT # Check if left shift key is held.
140
+ <Modifier.NONE: 0>
141
+ >>> not mod & tcod.event.Modifier.LSHIFT # Check if left shift key is NOT held.
142
+ True
143
+ >>> mod & tcod.event.Modifier.SHIFT and mod & tcod.event.Modifier.CTRL # Check if Shift+Control is held.
144
+ <Modifier.NONE: 0>
126
145
127
146
.. versionadded:: 12.3
128
147
"""
@@ -258,58 +277,28 @@ class KeyboardEvent(Event):
258
277
"""
259
278
Attributes:
260
279
type (str): Will be "KEYDOWN" or "KEYUP", depending on the event.
261
- scancode (int ): The keyboard scan-code, this is the physical location
280
+ scancode (Scancode ): The keyboard scan-code, this is the physical location
262
281
of the key on the keyboard rather than the keys symbol.
263
- sym (int): The keyboard symbol.
264
- mod (int): A bitmask of the currently held modifier keys.
265
-
266
- You can use the following to check if a modifier key is held:
267
-
268
- * `tcod.event.KMOD_LSHIFT`
269
- Left shift bit.
270
- * `tcod.event.KMOD_RSHIFT`
271
- Right shift bit.
272
- * `tcod.event.KMOD_LCTRL`
273
- Left control bit.
274
- * `tcod.event.KMOD_RCTRL`
275
- Right control bit.
276
- * `tcod.event.KMOD_LALT`
277
- Left alt bit.
278
- * `tcod.event.KMOD_RALT`
279
- Right alt bit.
280
- * `tcod.event.KMOD_LGUI`
281
- Left meta key bit.
282
- * `tcod.event.KMOD_RGUI`
283
- Right meta key bit.
284
- * `tcod.event.KMOD_SHIFT`
285
- ``tcod.event.KMOD_LSHIFT | tcod.event.KMOD_RSHIFT``
286
- * `tcod.event.KMOD_CTRL`
287
- ``tcod.event.KMOD_LCTRL | tcod.event.KMOD_RCTRL``
288
- * `tcod.event.KMOD_ALT`
289
- ``tcod.event.KMOD_LALT | tcod.event.KMOD_RALT``
290
- * `tcod.event.KMOD_GUI`
291
- ``tcod.event.KMOD_LGUI | tcod.event.KMOD_RGUI``
292
- * `tcod.event.KMOD_NUM`
293
- Num lock bit.
294
- * `tcod.event.KMOD_CAPS`
295
- Caps lock bit.
296
- * `tcod.event.KMOD_MODE`
297
- AltGr key bit.
282
+ sym (KeySym): The keyboard symbol.
283
+ mod (Modifier): A bitmask of the currently held modifier keys.
298
284
299
285
For example, if shift is held then
300
- ``event.mod & tcod.event.KMOD_SHIFT `` will evaluate to a true
286
+ ``event.mod & tcod.event.Modifier.SHIFT `` will evaluate to a true
301
287
value.
302
288
303
289
repeat (bool): True if this event exists because of key repeat.
290
+
291
+ .. versionchanged:: 12.5
292
+ `scancode`, `sym`, and `mod` now use their respective enums.
304
293
"""
305
294
306
295
def __init__ (
307
296
self , scancode : int , sym : int , mod : int , repeat : bool = False
308
297
):
309
298
super ().__init__ ()
310
- self .scancode = scancode
311
- self .sym = sym
312
- self .mod = mod
299
+ self .scancode = Scancode ( scancode )
300
+ self .sym = KeySym ( sym )
301
+ self .mod = Modifier ( mod )
313
302
self .repeat = repeat
314
303
315
304
@classmethod
0 commit comments