Keyboard Sensor: getKeyStatus

getKeyStatus(keycode)
  • Returns the status of a key

Return Type: 
  • integer

Return Values:

  • 0 = KX_INPUT_NONE = not active
  • 1 = KX_INPUT_JUST_ACTIVATED= just pressed
  • 2 = KX_INPUT_ACTIVE = active
  • 3 = KX_INPUT_JUST_RELEASED = released

keycode:

  • Type:  integer
Keyboard Sensor:
  • When the selected key is pressed, it sends one positive pulse to the connected controller(s).
     
  • When the selected key is released, it sends one negative pulse to the connected controller(s).
Sample Code


################  Get the status of a key
  
# import bge module

import bge

# get the controller
cont = bge.logic.getCurrentController()

# get the sensor attached to the controller
# my sensor is named sensor

sen = cont.sensors["sensor"]

# get status of the w key
# key code for the w key is 119

key_status = sen.getKeyStatus(119)