Keyboard sensor

With the Keyboard sensor, you will push on a button to send a positive pulse and release it to send a negative pulse.

Option(s) of the Keyboard sensor :

  • Key : Keyboard Key that you want to trigger the sensor
  • All Keys : Select this if you want every keyboard key to trigger the sensor
  • First Modifier : A keyboard key which needs to be pressed while pressing the main key (Leave blank for none)
  • Second Modifier : A keyboard key which needs to be pressed while pressing the main key (Leave blank for none)
  • Log Toggle : Log toggle turns on/off saving of all keystrokes entered to a string property
    • Name of a Boolean Property : If the boolean Property is set on TRUE, All keystrokes will be saved as a string to the Target (string property)
    • Key, First Modifier, Second Modifier and All keys can be left blank
  • Target : Name of the String Property the keystrokes will be saved to
    • When the Log Toggle = True, all the keystrokes will be saved to Target string property
    • Saves all the keystrokes. Not just the key(s) selected
    • Key, First Modifier, Second Modifier and All keys can be left blank

Python :

# import bge module
import bge
 
# get the controller
cont = bge.logic.getCurrentController()
 
# get the sensor attached to the controller
# my sensor is named Trigger
sen = cont.sensors["Trigger"]
  • sen.key : the key that triggers the keyboard sensor list of key codes
  • sen.events : Returns a list of the keys that have been pressed/held/released
  • sen.getKeyStatus : Returns the status of a key ( 0 = KX_INPUT_NONE = not active , 1 = KX_INPUT_JUST_ACTIVATED= just pressed , 2 = KX_INPUT_ACTIVE = active , 3 = KX_INPUT_JUST_RELEASED = released )
  • sen.hold1 : the key assigned to First Modifier (0 if wasn't assigned )
  • sen.hold2 : the key assigned to Second Modifier (0 if wasn't assigned )
  • sen.toggleProperty : the name of the Bool property
  • sen.targetProperty : the name of the String property
  • sen.useAllKeys : gets/sets if the All Keys button is used
Unless otherwise stated, the content of this page is licensed under Creative Commons Attribution-ShareAlike 3.0 License