Keyboard Sensor: events

events
  • Returns a list of the keys that have been pressed/held/released in this frame.

Type: 
  • list [ keycode, state]

keycode:

  • Type:  integer
state:
  • Type:  integer
  • 0 = not active
  • 1 = just pressed
  • 2 = active
  • 3 = released
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 a list of keys currently pressed/held/released

# 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 a list of keys currently pressed/held/released
key_list = sen.events