Mperonen
(Mperonen)
May 16, 2013, 5:30am
1
I’m trying to figure out a simple way to see if a player is pressing several buttons and to execute running, etc.
for example WKEY is for walking forward,
but SHIFT +WKEY is for running.
so far I have managed to get keyboard sensor (keyboard.events) to give only one key as input.
I have keyboard with “All Keys” on, connected to Python module with the following:
keyboard = cont.sensors['Keyboard']
for key, status in keyboard.events:
if status == bge.logic.KX_INPUT_ACTIVE:
if key == WKEY:
#Execute walk
Simple, use logic.
Either have two different sensors connected to one (different) AND controller, and have that controller connected to your Sprint movement actuator.
Or, you could have a separate sensor and put ‘Shift’ in the “Modifier” box of the keyboard sensor, and put ‘W’ in the “Key” box. Then have that connect separately to the Sprint actuator.
1 Like
agoose77
(agoose77)
May 16, 2013, 6:37am
3
You’re looping through and checking if each one is true. Instead, just poll each one in the active_events:
from bge import logic, events
keyboard = logic.keyboard
a_key = keyboard.events.get(events.AKEY) == logic.KX_INPUT_ACTIVE
b_key = keyboard.events.get(events.BKEY) == logic.KX_INPUT_ACTIVE
or make a helper function:
from bge import logic, events
keyboard = logic.keyboard
def check_active(keyboard, key):
return keyboard.events.get(key) == logic.KX_INPUT_ACTIVE
a_key = check_active(keyboard, events.AKEY)