Class SCA_KeyboardSensor (2.48)


Methods
getCurrentlyPressedKeys getPressedKeys
getHold1 setHold1
getHold2 setHold2
getKey setKey
 
Variables
---------- ----------
 
Constants
---------- ----------

Inherited Methods:  Class SCA_ISensor
getFrequency reset
getInvert setFrequency
getLevel setInvert
getUseNegPulseMode setLevel
getUsePosPulseMode setUseNegPulseMode
isPositive setUsePosPulseMode
isTriggered ----------

Inherited Methods:  Class SCA_ILogicBrick
getExecutePriority setExecutePriority
getOwner ----------

Inherited Methods:  Class PyObjectPlus
isA ----------

Inherited Methods:  Class Value
getName ----------



Methods




Note:
A list of the keycodes follow this section.

getCurrentlyPressedKeys

getCurrentlyPressedKeys()

Returns a list of the keys that are being pressed in this frame.
 (None is returned if there aren't any keys being pressed.)

Return type:  list [ keycode, state]

keycode:
    See list of key codes at bottom of this section.

state:
1 = just pressed
2 = being held down

Sample Code

# get controller
controller = GameLogic.getCurrentController()

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

# get a list of the keys currently pressed
list = sen.getCurrentlyPressedKeys()

getHold1

getHold1()

Returns the key that was assigned to Hold1.  (0 is returned if a key wasn't assigned.)

Return:
Keycode:
Type: Integer


keycode:
See list of key codes at bottom of this section.

Note:
Hold1 and Hold2 return different keycodes for the Shift Modifiers, Arrow Keys, Numberpad Keys, Function Keys and Other Keys

Sample Code

# get controller
controller = GameLogic.getCurrentController()

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

# get the keycode for Hold1
list = sen.getHold1()

getHold2

getHold2()

Returns the key that was assigned to Hold2.  (0 is returned if a key wasn't assigned.)

Return:
Keycode:
Type: Integer


keycode:
See list of key codes at bottom of this section.

Note:
Hold1 and Hold2 return different keycodes for the Shift Modifiers, Arrow Keys, Numberpad Keys, Function Keys and Other Keys

Sample Code

# get controller
controller = GameLogic.getCurrentController()

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

# get the keycode for Hold2
list = sen.getHold2()

getKey

getKey()

Returns the keycode for the key that triggers the sensor.

Return type:  integer
 
See list of key codes at bottom of this section.

Note:
If the 'All keys' button is selected, it always returns 0.

Sample Code

# get controller
controller = GameLogic.getCurrentController()

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

# get key that triggers sensor
key = sen.getKey()

getPressedKeys

getPressedKeys()

Returns a list of the keys that have been either pressed or released in this frame.

Return type:  list [ keycode, state]

keycode:
See list of key codes at bottom of this section.

state:
1 = just pressed

3 = released

Sample Code

# get controller
controller = GameLogic.getCurrentController()

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

# get keys pressed or released
list = sen.getPressedKeys()

setHold1

setHold1(keycode)

Sets the Hold1 key.

keycode:
Type:  integer.
See list of key codes at bottom of this section.

Note:
Hold1 and Hold2 use different keycodes for the Shift Modifiers, Arrow Keys, Numberpad Keys, Function Keys and Other Keys

Sample Code

# get controller
controller = GameLogic.getCurrentController()

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

# keycode for A key is 97
keycode = 97

# set Hold1 key
sen.setHold1(keycode)

setHold2

setHold2(keycode)

Sets the Hold2 key.

keycode:
Type:  integer.
See list of key codes at bottom of this section.

Note:
Hold1 and Hold2 use different keycodes for the Shift Modifiers, Arrow Keys, Numberpad Keys, Function Keys and Other Keys

Sample Code

# get controller
controller = GameLogic.getCurrentController()

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

# keycode for A key is 97
keycode = 97

# set Hold2 key
sen.setHold2(keycode)

setKey

setKey(keycode)

Sets the key that triggers the sensor.

keycode:
Type:  integer.
See list of key codes at bottom of this section.

Sample Code

# get controller
controller = GameLogic.getCurrentController()

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

# keycode for A key is 97
keycode = 97

# set A key to trigger sensor
sen.setKey(keycode)


Key Codes



Note:

Alphabet & Number Keys:
Key, Hold 1 and Hold2 all use the same key codes.
Shift Modifiers, Arrow Keys, Numberpad Keys, Function Keys and Other Keys:
Key use one set of key codes.
Hold 1 and Hold2 use a different set of key codes.



Alphabet Keys

Keycodes for Key, Hold1 and Hold2


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

Keycodes for Key, Hold1 and Hold2

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



Shift Modifiers

Keycodes for Key

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



Keycodes for Hold1 and Hold2

CAPSLOCKKEY = ?
LEFTCTRLKEY = 212
LEFTALTKEY = 213
RIGHTALTKEY = 214
RIGHTCTRLKEY = 215
RIGHTSHIFTKEY = 216
LEFTSHIFTKEY = 217



Arrow Keys

Keycodes for Key

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



 Keycodes for Hold1 and Hold2
 
LEFTARROWKEY = 137
DOWNARROWKEY = 138
RIGHTARROWKEY = 139
UPARROWKEY = 140



Numberpad Keys

Keycodes for Key

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



Keycodes for Hold1 and Hold2
   
PAD0 =150
PAD1 = 151
PAD2 = 152
PAD3 = 153
PAD4 = 154
PAD5 = 155
PAD6 = 156
PAD7 = 157
PAD8 = 158
PAD9 = 159
PADPERIOD = 199
PADSLASHKEY = 161
PADASTERKEY = 160
PADMINUS = 162
PADENTER = 163
PADPLUSKEY = 164



Function Keys

Keycodes for Key

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

Keycodes for Hold1 and Hold2
 
F1KEY = 300
F2KEY = 301
F3KEY = 302
F4KEY = 303
F5KEY = 304
F6KEY = 305
F7KEY = 306
F8KEY = 307
F9KEY = 308
F10KEY = 309
F11KEY = 310
F12KEY = 311
  

Other Keys

Keycodes for Key

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

Keycodes for Hold1 and Hold2

ACCENTGRAVEKEY = 229
BACKSLASHKEY = 233
BACKSPACEKEY = 223
COMMAKEY = 227
DELKEY = 224
ENDKEY = 170
EQUALKEY = 234
ESCKEY = 218
HOMEKEY = 167
INSERTKEY = 166
LEFTBRACKETKEY = 235
LINEFEEDKEY = ?
MINUSKEY = 230
PAGEDOWNKEY = 169
PAGEUPKEY = 168
PAUSEKEY = 165
PERIODKEY = 226
QUOTEKEY = 228
RIGHTBRACKETKEY = 236
RETKEY = 220
SEMICOLONKEY = 225
SLASHKEY = 232
SPACEKEY = 221
TABKEY = 219



Blender 3D
Game Engine