Blender 3D game engine: GameKeys Module
Methods:
EventToString ----------
Variables:
---------- ----------
Constants:
---------- ----------



Instance Methods

EventToString

EventToString(keyCode)

Returns the name of a keycode.

Return Type:  string

keyCode:
Type:  integer

Note:
There is a list of the keycodes at the bottom of this page.

Sample Code

# import GameKeys module
import GameKeys

# get the controller
controller = GameLogic.getCurrentController()

# get the keyboard sensor named sensor
sen = controller.getSensor("sensor")

# Keyboard Sensor is using the All keys buttons

# get information about the key pressed  
keyInfo = sen.getPressedKeys()

# extract the keycode from the info
event = keyInfo[0][0]

# get the key name
key = GameKeys.EventToString(event)

Alphabet Keys

AKEY
BKEY
CKEY
DKEY
EKEY
FKEY
GKEY
HKEY
IKEY
JKEY
KKEY
LKEY
MKEY
NKEY
OKEY
PKEY
QKEY
RKEY
SKEY
TKEY
UKEY
VKEY
WKEY
XKEY
YKEY
ZKEY

Number Keys

ZEROKEY
ONEKEY
TWOKEY
THREEKEY
FOURKEY
FIVEKEY
SIXKEY
SEVENKEY
EIGHTKEY
NINEKEY



Shift Modifiers

CAPSLOCKKEY


LEFTALTKEY
LEFTCTRLKEY
LEFTSHIFTKEY
RIGHTALTKEY
RIGHTCTRLKEY
RIGHTSHIFTKEY

Arrow Keys

DOWNARROWKEY
LEFTARROWKEY
RIGHTARROWKEY
UPARROWKEY



Numberpad Keys

PAD0
PAD1
PAD2
PAD3
PAD4
PAD5
PAD6
PAD7
PAD8
PAD9
PADPERIOD
PADSLASHKEY
PADASTERKEY
PADMINUS
PADENTER
PADPLUSKEY




Function Keys

F1KEY
F2KEY
F3KEY = 164
F4KEY
F5KEY
F6KEY = 167
F7KEY
F8KEY
F9KEY = 170
F10KEY
F11KEY
F12KEY = 173

 Other Keys

ACCENTGRAVEKEY
BACKSLASHKEY
BACKSPACEKEY
COMMAKEY
DELKEY
ENDKEY
EQUALKEY
ESCKEY
HOMEKEY
INSERTKEY
LEFTBRACKETKEY
LINEFEEDKEY
MINUSKEY
PAGEDOWNKEY
PAGEUPKEY
PAUSEKEY
PERIODKEY
QUOTEKEY
RIGHTBRACKETKEY
RETKEY
SEMICOLONKEY
SLASHKEY
SPACEKEY
TABKEY

Example:  Assigning a key to a keyboard sensor

# import GameKeys module
import GameKeys

# get the current controller
controller = GameLogic.getCurrentController()

# get the keyboard sensor named assignKey
key = controller.getSensor("assignKey")

# Assign the A key to the keyboard sensor
key.setKey(GameKeys.AKEY)




Blender 3d game engine: keyboard sensor keycodes


Alphabet Keys

AKEY =  97
BKEY =  98
CKEY =  99
DKEY = 100
EKEY = 101
FKEY = 102
GKEY = 103
HKEY = 104
IKEY = 105
JKEY = 106
KKEY = 107
LKEY = 108
MKEY = 109
NKEY = 110
OKEY = 111
PKEY = 112
QKEY = 113
RKEY = 114
SKEY = 115
TKEY = 116
UKEY = 117
VKEY = 118
WKEY = 119
XKEY = 120
YKEY = 121
ZKEY = 122

 

Number Keys

 ZEROKEY = 48
ONEKEY = 49
TWOKEY = 50
THREEKEY = 51
FOURKEY = 52
FIVEKEY = 53
SIXKEY = 54
SEVENKEY = 55
EIGHTKEY = 56
NINEKEY = 57



Shift Modifiers

CAPSLOCKKEY = ?
LEFTCTRLKEY = 124
LEFTALTKEY = 125
RIGHTALTKEY = 126
RIGHTCTRLKEY = 127
RIGHTSHIFTKEY = 128
LEFTSHIFTKEY = 129



Arrow Keys

LEFTARROWKEY = 143
DOWNARROWKEY = 144
RIGHTARROWKEY = 145
UPARROWKEY = 146



Numberpad Keys

PAD0 =158
PAD1 = 151
PAD2 = 147
PAD3 = 152
PAD4 = 148
PAD5 = 153
PAD6 = 149
PAD7 = 154
PAD8 = 150
PAD9 = 155
PADPERIOD = 156
PADSLASHKEY = 157
PADASTERKEY = 42
PADMINUS = 154
PADENTER = 160
PADPLUSKEY = 161



Function Keys

F1KEY = 162
F2KEY = 163
F3KEY = 164
F4KEY = 165
F5KEY = 166
F6KEY = 167
F7KEY = 168
F8KEY = 169
F9KEY = 170
F10KEY = 171
F11KEY = 172
F12KEY = 173
 

Other Keys

ACCENTGRAVEKEY = 137
BACKSLASHKEY = 139
BACKSPACEKEY = 133
COMMAKEY = 44
DELKEY = 134
ENDKEY = ? 
EQUALKEY = 140
ESCKEY = 130
HOMEKEY = 176
INSERTKEY = 175
LEFTBRACKETKEY = 141
LINEFEEDKEY = ?
MINUSKEY = 45
PAGEDOWNKEY = 178
PAGEUPKEY = 177
PAUSEKEY = 174
PERIODKEY = 46
QUOTEKEY = 136
RIGHTBRACKETKEY = 142
RETKEY = 13
SEMICOLONKEY = 135
SLASHKEY = 138
SPACEKEY = 32
TABKEY = 131


Blender 3D
Game Engine
Rapid prototyping for 3D games. Test realtime 3D gameplay without having to compile the game code. 3D game models automatically added.  GLSL shaders. Normal Mapping and Parallax Mapping. All OpenGL Lighting modes. This includes transparencies, animated and reflection mapped textures. Multiple textures and materials. UV mapping. Per-pixel lighting and dynamic lighting.  Uses Bullet Physics. Soft body dynamics. Rigid body dynamics. Collision detection and dynamics simulation. Collision bounds of all types. Car physics engine with full support for vehicle dynamics. (Spring reactions, stiffness, damping, tire friction etc.).