This module holds key constants for the SCA_KeyboardSensor.
# Set a connected keyboard sensor to accept F1
import bge
co = bge.logic.getCurrentController()
# 'Keyboard' is a keyboard sensor
sensor = co.sensors["Keyboard"]
sensor.key = bge.events.F1KEY
# Do the all keys thing
import bge
co = bge.logic.getCurrentController()
# 'Keyboard' is a keyboard sensor
sensor = co.sensors["Keyboard"]
for key,status in sensor.events:
# key[0] == bge.events.keycode, key[1] = status
if status == bge.logic.KX_INPUT_JUST_ACTIVATED:
if key == bge.events.WKEY:
# Activate Forward!
if key == bge.events.SKEY:
# Activate Backward!
if key == bge.events.AKEY:
# Activate Left!
if key == bge.events.DKEY:
# Activate Right!
# The all keys thing without a keyboard sensor (but you will
# need an always sensor with pulse mode on)
import bge
# Just shortening names here
keyboard = bge.logic.keyboard
JUST_ACTIVATED = bge.logic.KX_INPUT_JUST_ACTIVATED
if keyboard.events[bge.events.WKEY] == JUST_ACTIVATED:
print("Activate Forward!")
if keyboard.events[bge.events.SKEY] == JUST_ACTIVATED:
print("Activate Backward!")
if keyboard.events[bge.events.AKEY] == JUST_ACTIVATED:
print("Activate Left!")
if keyboard.events[bge.events.DKEY] == JUST_ACTIVATED:
print("Activate Right!")
Return the string name of a key event. Will raise a ValueError error if its invalid.
Parameters: | event (int) – key event constant from bge.events or the keyboard sensor. |
---|---|
Return type: | string |
Return the string name of a key event. Returns an empty string if the event cant be represented as a character.
Parameters: |
|
---|---|
Return type: | string |