File: keymaps.py

package info (click to toggle)
python-moderngl-window 2.4.6-1
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 69,220 kB
  • sloc: python: 11,387; makefile: 21
file content (17 lines) | stat: -rw-r--r-- 738 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
from collections import namedtuple
from typing import Callable

from moderngl_window.context.base.keys import BaseKeys

KeyMap = namedtuple("KeyMap", ["UP", "DOWN", "LEFT", "RIGHT", "FORWARD", "BACKWARD"])

# A factory is used since we cannot deduce the keys format before run time, as they are
# induced by the window software used.
# Therefore, the factory takes as a parameter the keys used, and return a keymap instance.
KeyMapFactory = Callable[[BaseKeys], KeyMap]
AZERTY: KeyMapFactory = lambda keys: KeyMap(
    UP=keys.A, DOWN=keys.E, LEFT=keys.Q, RIGHT=keys.D, FORWARD=keys.Z, BACKWARD=keys.S
)
QWERTY: KeyMapFactory = lambda keys: KeyMap(
    UP=keys.Q, DOWN=keys.E, LEFT=keys.A, RIGHT=keys.D, FORWARD=keys.W, BACKWARD=keys.S
)