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
Constants¶
Mouse Keys¶
- bge.events.LEFTMOUSE¶
- Value
116
- bge.events.MIDDLEMOUSE¶
- Value
117
- bge.events.RIGHTMOUSE¶
- Value
118
- bge.events.WHEELUPMOUSE¶
- Value
120
- bge.events.WHEELDOWNMOUSE¶
- Value
121
- bge.events.MOUSEX¶
- Value
122
- bge.events.MOUSEY¶
- Value
123
Alphabet Keys¶
- bge.events.AKEY¶
- Value
23
- bge.events.BKEY¶
- Value
24
- bge.events.CKEY¶
- Value
25
- bge.events.DKEY¶
- Value
26
- bge.events.EKEY¶
- Value
27
- bge.events.FKEY¶
- Value
28
- bge.events.GKEY¶
- Value
29
- bge.events.HKEY¶
- Value
30
- bge.events.IKEY¶
- Value
31
- bge.events.JKEY¶
- Value
32
- bge.events.KKEY¶
- Value
33
- bge.events.LKEY¶
- Value
34
- bge.events.MKEY¶
- Value
35
- bge.events.NKEY¶
- Value
36
- bge.events.OKEY¶
- Value
37
- bge.events.PKEY¶
- Value
38
- bge.events.QKEY¶
- Value
39
- bge.events.RKEY¶
- Value
40
- bge.events.SKEY¶
- Value
41
- bge.events.TKEY¶
- Value
42
- bge.events.UKEY¶
- Value
43
- bge.events.VKEY¶
- Value
44
- bge.events.WKEY¶
- Value
45
- bge.events.XKEY¶
- Value
46
- bge.events.YKEY¶
- Value
47
- bge.events.ZKEY¶
- Value
48
Number Keys¶
- bge.events.ZEROKEY¶
- Value
13
- bge.events.ONEKEY¶
- Value
14
- bge.events.TWOKEY¶
- Value
15
- bge.events.THREEKEY¶
- Value
16
- bge.events.FOURKEY¶
- Value
17
- bge.events.FIVEKEY¶
- Value
18
- bge.events.SIXKEY¶
- Value
19
- bge.events.SEVENKEY¶
- Value
20
- bge.events.EIGHTKEY¶
- Value
21
- bge.events.NINEKEY¶
- Value
22
Modifiers Keys¶
- bge.events.CAPSLOCKKEY¶
- Value
49
- bge.events.LEFTCTRLKEY¶
- Value
50
- bge.events.LEFTALTKEY¶
- Value
51
- bge.events.RIGHTALTKEY¶
- Value
52
- bge.events.RIGHTCTRLKEY¶
- Value
53
- bge.events.RIGHTSHIFTKEY¶
- Value
54
- bge.events.LEFTSHIFTKEY¶
- Value
55
Arrow Keys¶
- bge.events.LEFTARROWKEY¶
- Value
69
- bge.events.DOWNARROWKEY¶
- Value
70
- bge.events.RIGHTARROWKEY¶
- Value
71
- bge.events.UPARROWKEY¶
- Value
72
Numberpad Keys¶
- bge.events.PAD0¶
- Value
84
- bge.events.PAD1¶
- Value
77
- bge.events.PAD2¶
- Value
73
- bge.events.PAD3¶
- Value
78
- bge.events.PAD4¶
- Value
74
- bge.events.PAD5¶
- Value
79
- bge.events.PAD6¶
- Value
75
- bge.events.PAD7¶
- Value
80
- bge.events.PAD8¶
- Value
76
- bge.events.PAD9¶
- Value
71
- bge.events.PADPERIOD¶
- Value
82
- bge.events.PADSLASHKEY¶
- Value
83
- bge.events.PADASTERKEY¶
- Value
9
- bge.events.PADMINUS¶
- Value
85
- bge.events.PADENTER¶
- Value
86
- bge.events.PADPLUSKEY¶
- Value
87
Function Keys¶
- bge.events.F1KEY¶
- Value
88
- bge.events.F2KEY¶
- Value
89
- bge.events.F3KEY¶
- Value
90
- bge.events.F4KEY¶
- Value
91
- bge.events.F5KEY¶
- Value
92
- bge.events.F6KEY¶
- Value
93
- bge.events.F7KEY¶
- Value
94
- bge.events.F8KEY¶
- Value
95
- bge.events.F9KEY¶
- Value
96
- bge.events.F10KEY¶
- Value
97
- bge.events.F11KEY¶
- Value
98
- bge.events.F12KEY¶
- Value
99
- bge.events.F13KEY¶
- Value
100
- bge.events.F14KEY¶
- Value
101
- bge.events.F15KEY¶
- Value
102
- bge.events.F16KEY¶
- Value
103
- bge.events.F17KEY¶
- Value
104
- bge.events.F18KEY¶
- Value
105
- bge.events.F19KEY¶
- Value
106
Other Keys¶
- bge.events.ACCENTGRAVEKEY¶
- Value
63
- bge.events.BACKSLASHKEY¶
- Value
65
- bge.events.BACKSPACEKEY¶
- Value
59
- bge.events.COMMAKEY¶
- Value
10
- bge.events.DELKEY¶
- Value
60
- bge.events.ENDKEY¶
- Value
113
- bge.events.EQUALKEY¶
- Value
66
- bge.events.ESCKEY¶
- Value
56
- bge.events.HOMEKEY¶
- Value
110
- bge.events.INSERTKEY¶
- Value
109
- bge.events.LEFTBRACKETKEY¶
- Value
67
- bge.events.LINEFEEDKEY¶
- Value
58
- bge.events.MINUSKEY¶
- Value
11
- bge.events.PAGEDOWNKEY¶
- Value
112
- bge.events.PAGEUPKEY¶
- Value
111
- bge.events.PAUSEKEY¶
- Value
108
- bge.events.PERIODKEY¶
- Value
12
- bge.events.QUOTEKEY¶
- Value
62
- bge.events.RIGHTBRACKETKEY¶
- Value
68
- bge.events.RETKEY¶
Warning
Deprecated, use
bge.events.ENTERKEY()
instead.- Value
7
- bge.events.ENTERKEY¶
- Value
7
- bge.events.SEMICOLONKEY¶
- Value
61
- bge.events.SLASHKEY¶
- Value
64
- bge.events.SPACEKEY¶
- Value
8
- bge.events.TABKEY¶
- Value
57