diff options
Diffstat (limited to 'doc/python_api/rst/bge.events.rst')
-rw-r--r-- | doc/python_api/rst/bge.events.rst | 94 |
1 files changed, 47 insertions, 47 deletions
diff --git a/doc/python_api/rst/bge.events.rst b/doc/python_api/rst/bge.events.rst index 8dbded6a3fe..42135926fda 100644 --- a/doc/python_api/rst/bge.events.rst +++ b/doc/python_api/rst/bge.events.rst @@ -12,53 +12,53 @@ This module holds key constants for the SCA_KeyboardSensor. .. code-block:: python - # 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 - -.. code-block:: python - - # 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! - -.. code-block:: python - - # 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!") + # 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 + + code-block:: python + + # 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! + + code-block:: python + + # 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!") ********* |