Keyboard: EventToCharacter

EventToCharacter(keyCode, shift)
  • Returns the Keyboard letter/number/etc.
     
  • Return Type: string

keyCode: shift:
  • Type:  Bool
  • 1 = True = Shift key held down
  • 0 = False = Shift key not being held down
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()

# 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 keyInfo
keyCode = keyInfo[0][0]

# return the pressed key as a capital letter
shift = True

# get keyboard letter
keyCap = bge.events.EventToCharacter(keyCode, shift)