Exemplo n.º 1
0
class InputMapperTecladoMouse(InputMapper):

    # teclas accion defecto
    TeclasAccionDefecto = {
        KeyboardButton.enter(): InputMapper.AccionArrojar,
        KeyboardButton.space(): InputMapper.AccionAscender,
        KeyboardButton.tab(): InputMapper.AccionUsar,
        KeyboardButton.control(): InputMapper.AccionAgachar,
        KeyboardButton.alt(): InputMapper.AccionAgarrar,
        KeyboardButton.asciiKey(b"c"): InputMapper.AccionFlotar,
        KeyboardButton.asciiKey(b"x"): InputMapper.AccionSoltar,
        KeyboardButton.asciiKey(b"z"): InputMapper.AccionFrenar,
        KeyboardButton.asciiKey(b"w"): InputMapper.AccionAvanzar,
        KeyboardButton.asciiKey(b"a"): InputMapper.AccionAvanzar,
        KeyboardButton.asciiKey(b"s"): InputMapper.AccionAvanzar,
        KeyboardButton.asciiKey(b"d"): InputMapper.AccionAvanzar,
        KeyboardButton.asciiKey(b"r"): InputMapper.AccionAvanzar,
        KeyboardButton.asciiKey(b"f"): InputMapper.AccionAvanzar
    }

    # teclas parametro defecto
    TeclasParamDefecto = {
        KeyboardButton.asciiKey(b"w"): InputMapper.ParametroAdelante,
        KeyboardButton.asciiKey(b"a"): InputMapper.ParametroIzquierda,
        KeyboardButton.asciiKey(b"s"): InputMapper.ParametroAtras,
        KeyboardButton.asciiKey(b"d"): InputMapper.ParametroDerecha,
        KeyboardButton.asciiKey(b"r"): InputMapper.ParametroArriba,
        KeyboardButton.asciiKey(b"f"): InputMapper.ParametroAbajo,
        KeyboardButton.asciiKey(b"q"):
        InputMapper.ParametroGirando | InputMapper.ParametroIzquierda,
        KeyboardButton.asciiKey(b"e"):
        InputMapper.ParametroGirando | InputMapper.ParametroDerecha,
        KeyboardButton.shift(): InputMapper.ParametroRapido,
        KeyboardButton.asciiKey(b"v"): InputMapper.ParametroLento
    }

    def __init__(self, base):
        InputMapper.__init__(self, base)

    def update(self):
        # parametros
        self.parametros = InputMapper.ParametroNulo
        for tecla, parametro in InputMapperTecladoMouse.TeclasParamDefecto.items(
        ):
            if self.isButtonDown(tecla):
                self.parametros |= parametro
        # acciones
        self.accion = InputMapper.AccionNula
        for tecla, accion in InputMapperTecladoMouse.TeclasAccionDefecto.items(
        ):
            if self.isButtonDown(tecla):
                self.accion = accion
                break
Exemplo n.º 2
0
def test_keyboardbutton_ascii():
    assert KeyboardButton.space() == KeyboardButton.ascii_key(' ')
    assert KeyboardButton.backspace() == KeyboardButton.ascii_key('\x08')
    assert KeyboardButton.tab() == KeyboardButton.ascii_key('\x09')
    assert KeyboardButton.enter() == KeyboardButton.ascii_key('\x0d')
    assert KeyboardButton.escape() == KeyboardButton.ascii_key('\x1b')

    assert KeyboardButton.ascii_key(' ').name == 'space'
    assert KeyboardButton.ascii_key('\x08').name == 'backspace'
    assert KeyboardButton.ascii_key('\x09').name == 'tab'
    assert KeyboardButton.ascii_key('\x0d').name == 'enter'
    assert KeyboardButton.ascii_key('\x1b').name == 'escape'
    assert KeyboardButton.ascii_key('\x7f').name == 'delete'

    assert KeyboardButton.ascii_key('a').name == 'a'