Keyboard Sensor: key

key
  • gets/sets the Key that triggers the keyboard sensor

Type: 
  • 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 key that triggers the keyboard sensor

# import bge module
import bge

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

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

sen = cont.sensors["Gas"]

# get Key
keyCode = sen.key
 
Sample Code


################  Set the key that triggers the keyboard sensor

# import bge module
import bge

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

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

sen = cont.sensors["Gas"]

# set Key to Keyboard B Key
sen.key = bge.events.BKEY