Keyboard: EventToString

EventToString(keyCode)
  • Returns the Key Name
  • Return Type:  string

keyCode:

Note:
  • Key Names:  AKEY, BKEY, CKEY, DKEY, EKEY, etc
Sample Code

################  get the Key Name for the key triggering the  keyboard sensor
 
# import bge module

import bge

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

# Keyboard Sensor is using the All keys buttons

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

# get information about the key pressed 
keyInfo = sen.events

# get the key code from keyCode
keyCode  =  keyInfo[0]

# return the pressed key as a Key Name
keyName = bge.events.EventToString(keyCode)