Alt/Ctrl/Enter/Shift/Space Bar Key Codes

Enter Key:
  • 13 or bge.events.ENTERKEY
Left Ctrl Key:
  • 124 or bge.events.LEFTCTRLKEY
Left Alt Key:
  • 125 or bge.events.LEFTALTKEY
Left Shift Key:
  • 129 or bge.events.LEFTSHIFTKEY
Return Key:
  • 13 or bge.events.RETKEY
Right Alt Key:
  • 126 or bge.events.RIGHTALTKEY
Right Ctrl Key:
  • 127 or bge.events.RIGHTCTRLKEY
Right Shift Key:
  • 128 or bge.events.RIGHTSHIFTKEY
Space Bar:
  • 32 or bge.events.SPACEKEY
Sample Code

################  get the Key Code for the key triggering the keyboard sensor

# import bge module
import bge

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

# get the keyboard sensor
# My keyboard sensor is named Keyboard_1
sen = cont.sensors["Keyboard_1"]

# get the keycode of the key that triggers sensor
keyCode = sen.key

Sample Code

################  set the Key Code for the key triggering the keyboard sensor

# import bge module
import bge

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

# get the keyboard sensor
# My keyboard sensor is named Keyboard_1
sen = cont.sensors["Keyboard_1"]

# use the left shift key to trigger the keyboard sensor
# Left Shift key: 129 or bge.events.LEFTSHIFTKEY
sen.key = bge.events.LEFTSHIFTKEY