Game Keys (bge.events)

Intro

This module holds key constants for the SCA_KeyboardSensor.

# Set a connected keyboard sensor to accept F1
import bge

co = bge.logic.getCurrentController()
# 'Keyboard' is a keyboard sensor
sensor = co.sensors["Keyboard"]
sensor.key = bge.events.F1KEY
# Do the all keys thing
import bge

co = bge.logic.getCurrentController()
# 'Keyboard' is a keyboard sensor
sensor = co.sensors["Keyboard"]

for key, input in sensor.inputs:
     # key[0] == bge.events.keycode = event.type, key[1] = input
     if bge.logic.KX_INPUT_JUST_ACTIVATED in input.queue:
             if key == bge.events.WKEY:
                     # Activate Forward!
             if key == bge.events.SKEY:
                     # Activate Backward!
             if key == bge.events.AKEY:
                     # Activate Left!
             if key == bge.events.DKEY:
                     # Activate Right!
# The all keys thing without a keyboard sensor (but you will
# need an always sensor with pulse mode on)
import bge

# Just shortening names here
keyboard = bge.logic.keyboard
JUST_ACTIVATED = bge.logic.KX_INPUT_JUST_ACTIVATED

if JUST_ACTIVATED in keyboard.inputs[bge.events.WKEY].queue:
     print("Activate Forward!")
if JUST_ACTIVATED in keyboard.inputs[bge.events.SKEY].queue:
     print("Activate Backward!")
if JUST_ACTIVATED in keyboard.inputs[bge.events.AKEY].queue:
     print("Activate Left!")
if JUST_ACTIVATED in keyboard.inputs[bge.events.DKEY].queue:
     print("Activate Right!")

Functions

bge.events.EventToString(event)

Return the string name of a key event. Will raise a ValueError error if its invalid.

Parameters:

event (int) – key event constant from bge.events or the keyboard sensor.

Return type:

string

bge.events.EventToCharacter(event, shift)

Return the string name of a key event. Returns an empty string if the event cant be represented as a character.

Parameters:
  • event (int) – key event constant from bge.events or the keyboard sensor.

  • shift (bool) – set to true if shift is held.

Return type:

string

Keys (Constants)

Mouse Keys

bge.events.LEFTMOUSE
bge.events.MIDDLEMOUSE
bge.events.RIGHTMOUSE
bge.events.BUTTON4MOUSE
bge.events.BUTTON5MOUSE
bge.events.BUTTON6MOUSE
bge.events.BUTTON7MOUSE
bge.events.WHEELUPMOUSE
bge.events.WHEELDOWNMOUSE
bge.events.MOUSEX
bge.events.MOUSEY

Keyboard Keys

Alphabet keys

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

Number keys

bge.events.ZEROKEY
bge.events.ONEKEY
bge.events.TWOKEY
bge.events.THREEKEY
bge.events.FOURKEY
bge.events.FIVEKEY
bge.events.SIXKEY
bge.events.SEVENKEY
bge.events.EIGHTKEY
bge.events.NINEKEY

Modifiers Keys

bge.events.CAPSLOCKKEY
bge.events.LEFTCTRLKEY
bge.events.LEFTALTKEY
bge.events.RIGHTALTKEY
bge.events.RIGHTCTRLKEY
bge.events.RIGHTSHIFTKEY
bge.events.LEFTSHIFTKEY

Arrow Keys

bge.events.LEFTARROWKEY
bge.events.DOWNARROWKEY
bge.events.RIGHTARROWKEY
bge.events.UPARROWKEY

Numberpad Keys

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

Function Keys

bge.events.F1KEY
bge.events.F2KEY
bge.events.F3KEY
bge.events.F4KEY
bge.events.F5KEY
bge.events.F6KEY
bge.events.F7KEY
bge.events.F8KEY
bge.events.F9KEY
bge.events.F10KEY
bge.events.F11KEY
bge.events.F12KEY
bge.events.F13KEY
bge.events.F14KEY
bge.events.F15KEY
bge.events.F16KEY
bge.events.F17KEY
bge.events.F18KEY
bge.events.F19KEY

Other Keys

bge.events.ACCENTGRAVEKEY
bge.events.BACKSLASHKEY
bge.events.BACKSPACEKEY
bge.events.COMMAKEY
bge.events.DELKEY
bge.events.ENDKEY
bge.events.EQUALKEY
bge.events.ESCKEY
bge.events.HOMEKEY
bge.events.INSERTKEY
bge.events.LEFTBRACKETKEY
bge.events.LINEFEEDKEY
bge.events.MINUSKEY
bge.events.PAGEDOWNKEY
bge.events.PAGEUPKEY
bge.events.PAUSEKEY
bge.events.PERIODKEY
bge.events.QUOTEKEY
bge.events.RIGHTBRACKETKEY
bge.events.RETKEY

Deprecated since version 0.0.1: Use ENTERKEY.

bge.events.ENTERKEY
bge.events.SEMICOLONKEY
bge.events.SLASHKEY
bge.events.SPACEKEY
bge.events.TABKEY