Exemplo n.º 1
0
    def setKey(self):
        self.objects["KEY"].color = self.COL_ICO  #(0, 0.5, 1, 1)
        self.objects["KEY_VALUE"].color = (1, 1, 1, 1)
        self.objects["KEY_VALUE"].text = "Press New Key..."

        KEY = "WAIT"
        for x in logic.keyboard.events:
            if logic.keyboard.events[x] == 1 and x != events.ESCKEY:
                KEY = events.EventToString(x)

        for y in logic.mouse.events:
            if y not in [events.MOUSEX, events.MOUSEY]:
                if logic.mouse.events[y] == 1:
                    KEY = events.EventToString(y)

        if logic.keyboard.events[events.ACCENTGRAVEKEY] == 1:
            if logic.keyboard.events[
                    events.LEFTSHIFTKEY] == 2 or logic.keyboard.events[
                        events.RIGHTSHIFTKEY] == 2:
                KEY = "NONE"

        if KEY != "WAIT":
            self.bind.updateBind(KEY)
            KEY = "DONE"

        if logic.keyboard.events[events.ESCKEY] == 1 or KEY == "DONE":
            self.objects["KEY_VALUE"].text = self.bind.input_name
            self.objects["KEY_VALUE"].color = self.COL_ICO
            return "END"

        return "Press Any Key... ESC to Cancel... TIDLE (~) to Set 'None'..."
Exemplo n.º 2
0
def isKeyboardInput(movableDirection, controller):
    keyboard = controller.sensors['keyboard']
    activeKeys = logic.keyboard.active_events

    if keyboard.positive:
        keyCode = keyboard.events[0][0]
        keyName = events.EventToString(keyCode)
        if keyName in BUTTON_CONFIG:
            return movableDirection == BUTTON_CONFIG[keyName]
    return False
Exemplo n.º 3
0
from bge import logic as G
from bge import events as GK

cont = G.getCurrentController()
owner = cont.owner
sensor = cont.sensors["s_keyboard"]

if sensor.positive:

    keylist = sensor.events

    # get only the first pressed key
    event = keylist[0]

    pressed_key = event[0]
    status = event[1]

    text = "the key number is: %d\n" % pressed_key
    text += "the key value is: %s\n" % GK.EventToString(pressed_key)
    text += "the character is: %s\n" % GK.EventToCharacter(
        pressed_key, 0)  # (key_code, captalize_flag)

    # optionally you can see the key status too if you want (just activated,
    # text += "the status is: %d\n" % status

    # press space to reset the initial text
    if pressed_key == GK.SPACEKEY:
        text = "Please, press any key."

    owner["Text"] = text
Exemplo n.º 4
0
# #############################

import bge
from bge import logic
from bge import events

cont = logic.getCurrentController()
owner = cont.owner
sensor = cont.sensors["s_keyboard"]

active_events = logic.keyboard.active_events
if len(active_events):

    text = ""
    # get only the first pressed key
    for key,status in active_events.items():

        text += "the key number is: %d\n" % key
        text += "the key value is: %s\n" % events.EventToString(key)
        text += "the character is: %s\n" % events.EventToCharacter(key, 0) # (key_code, captalize_flag)

        # optionally you can see the key status too if you want (just activated, 
        text += "the status is: %d\n" % status

        # press space to reset the initial text
        if key == events.SPACEKEY:
            text = "Please, press any key."
            break

    owner["Text"] = text