Blender 3D game engine: SCA_JoyKeyboardSensor
Methods:
getCurrentlyPressedKeys getPressedKeys
getHold1 setHold1
getHold2 setHold2
getKey setKey
Variables:
---------- ----------
Constants:
---------- ----------
Inherited
Methods:
getExecutePriority isPositive
getFrequency isTriggered
getInvert reset
getLevel setExecutePriority
getName setFrequency
getOwner setInvert
getUseNegPulseMode setLevel
getUsePosPulseMode setUseNegPulseMode
isA setUsePosPulseMode



Instance 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
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
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
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
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
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
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
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
sen = controller.getSensor("sensor")

# keycode for A key is 97
keycode = 97

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



Blender 3d game engine: keyboard sensor keycodes

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
 


Instance Methods: Inherited

getFrequency

getFrequency()

Returns the delay between repeated pulses.  

Return Type:  Integer
0 = no delay.

Sample Code

# get the controller
controller = GameLogic.getCurrentController()

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

# get sensor Frequency
pulseFreq = sen.getFrequency()

getInvert

getInvert()

Returns if sensor is set to activate on negative events.

Return Type:  Bool

True = sensor activated on negative events
False = sensor activated on positive events

Note:
It is supposed to return a bool.
1 = True
0 = False

It doesn't.  Instead it returns
1 = True
2  = False

Sample Code

# get the controller
controller = GameLogic.getCurrentController()

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

# trigger on negative pulse?
trigger = sen.getInvert()

getLevel

getLevel()

The Level button is a part of the State System.

Returns whether or not the level (Lvl) button is active.

Level button activated:
Deactivated mouse sensor is reactivated:
Checks to see if a mouse button is being pressed.
If it is, it sends a pulse to the controller.

Level button not activated:
Deactivated mouse sensor is reactivated:
Doesn't check to see if a mouse button is being pressed.
Doesn't send pulse to the controller.

Return Type:  Bool

1 = True = Level button active.
2 = False = Level button inactive.
Note:
Only works reliably when the sensor is connected to a single state.

Note:
It is supposed to return a bool.
1 = True
0 = False

It doesn't.  Instead it returns
1 = True
2  = False

Sample Code

# get the controller
controller = GameLogic.getCurrentController()

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

# send pulse when activated by State System?
sendPulse = sen.getLevel()

getUseNegPulseMode

getUseNegPulseMode()

Returns if sensor is set to use negative pulse.

Return Type:  Bool

1 = True = Use negative pulse
2 = False = Don't use negative pulse

Note:
It is supposed to return a bool.
1 = True
0 = False

It doesn't.  Instead it returns
1 = True
2  = False

Sample Code

# get the controller
controller = GameLogic.getCurrentController()

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

# trigger on negative pulse?
trigger = sen.getUseNegPulseMode()

getUsePosPulseMode

setBlendtime(blendtime)

Returns if sensor is set to use positive pulse.

Return Type:  Bool

1 = True = Use positive pulse
2 = False = Don't use positive pulse

Note:
It is supposed to return a bool.
1 = True
0 = False

It doesn't.  Instead it returns
1 = True
2  = False

Sample Code

# get the controller
controller = GameLogic.getCurrentController()

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

# trigger on positive pulse?
trigger = sen.getUsePosPulseMode()

isPositive

isPositive()

Returns True when sensor is activated.  False when it is deactivated.

Return Type:   Bool

1 = True = sensor activated
0 = False = sensor deactivated

Sample Code

# get the controller
controller = GameLogic.getCurrentController()

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

# sensor being activated?  Deactivated?
activated = sen.isPositive()

isTriggered

isTriggered()

Returns if sensor has triggered the controller

Return Type:   Bool

1 = True = sensor triggered controller
0 = False = sensor hasn't triggered controller

Sample Code

# get the controller
controller = GameLogic.getCurrentController()

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

# sensor triggered controller?
trigger = sen.isTriggered()

reset

reset()

Resets the sensor to it's initial state.  (ie. just activated)

Sample Code

# get the controller
controller = GameLogic.getCurrentController()

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

# reset the sensor
sen.reset()

setFrequency

setFrequency(freq)

Sets the delay between repeated pulses.  

freq: 
Type is integer.

0 = no delay.

Sample Code

# get the controller
controller = GameLogic.getCurrentController()

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

# set Frequency to no delay
sen.setFrequency(0)

setInvert

setInvert(inv)

Sets if  the sensor is to activate on negative events.

inv: 
Type: Bool.

  1 = True = activate on negative events
  0 = False = activate on positive events

Note:
True, False and 1, 0 work as expected

But
getInvert()
2 = False

setInvert(2)
sets it to True

Sample Code

# get the controller
controller = GameLogic.getCurrentController()

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

# set to activate on negative events
sen.setInvert(True)

setLevel

setLevel(activate)

The Level button is a part of the State System.

Sets whether or not the level (Lvl) button is active.

Level button activated:
Deactivated mouse sensor is reactivated:
Checks to see if a mouse button is being pressed.
If it is, it sends a pulse to the controller.

Level button not activated:
Deactivated mouse sensor is reactivated:
Doesn't check to see if a mouse button is being pressed.
Doesn't send pulse to the controller.


activate:
Type:  Bool

   1 or True = Level button active.
   0 or False = Level button inactive.

Note:
Only works reliably when the sensor is connected to a single state.

Note:
True, False and 1, 0 work as expected

But
getLevel()
2 = False

setLevel(2)
2 sets it to True

Sample Code

# get the controller
controller = GameLogic.getCurrentController()

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

# set level detector to True
sen.setLevel(True)

setUseNegPulseMode

setUseNegPulseMode(pulse)

Sets the sensor to use negative pulse mode.

pulse: 
 Type  =  Bool.

1 = True = Use negative pulse mode
0 = False = Use positive pulse mode

Note:
True, False and 1, 0 work as expected

But
getUseNegPulseMode()
2 = False

setUseNegPulseMode(2)
2 sets it to True

Sample Code

# get the controller
controller = GameLogic.getCurrentController()

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

# set to use on negative pulse
sen.setUseNegPulseMode(True)

setUsePosPulseMode

setUsePosPulseMode(pulse)

Sets the sensor to use positive pulse mode.

pulse: 
 Type  =  Bool.

1 = True = Use positive pulse mode
0 = False = Use negative pulse mode

Note:
True, False and 1, 0 work as expected

But
getUsePosPulseMode()
2 = False

setUsePosPulseMode(2)
2 sets it to True

Sample Code

# get the controller
controller = GameLogic.getCurrentController()

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

# set to use on positive pulse
sen.setUsePosPulseMode(True)



Instance Methods: Inherited

getExecutePriority

getExecutePriority()

Gets the execute priority of the logic brick

Return Type:  integer

Doesn't work:
Crashes Blender

Sample Code

# get the controller
controller = GameLogic.getCurrentController()

# get the actuator named act
act = controller.getActuator("act")

# get brick priority
priority = act.getExecutePriority()

getOwner

getOwner()

Gets the game object that owns the logic brick.

Return Type:  KX_GameObject

Sample Code

# get the controller
controller = GameLogic.getCurrentController()

# get the actuator named act
act = controller.getActuator("act")

# get brick owner
owner = act.getOwner()

setExecutePriority

setExecutePriority(priority)

Sets the execution priority of the logic brick.

priority:
   Type:  integer
0 is first
1 is second
etc.

Sample Code

# get the controller
controller = GameLogic.getCurrentController()

# get the actuator named act
act = controller.getActuator("act")

# set brick priority to be first
act.setExecutePriority(0)





isA

isA(Type)

Checks the Object type.
(KX_GameObject, SCA_ILogicBrick, KX_Scene, etc.)

Type:  String

Return Type:  Bool
1 = True
0 = False

Sample Code

# get the controller
controller = GameLogic.getCurrentController()

# get the object controller attached to
owner = controller.getOwner()

# is owner a GameObject?
gameObject = owner.isA("KX_GameObject")





getName

getName()

Returns the name of actuator

Return Type:  string

Sample Code

# get the controller
controller = GameLogic.getCurrentController()

# get a list of the attached actuators 
actList = controller.getActuators()

# loop through the list of actuators
for act in actList:

# look for an actuator named "RocketMotion"
if act.getName() == "RocketMotion":

# use it
GameLogic.addActiveActuator(act, True)

# Done.  Break out of loop
break


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.).