A bit of bge.events work:
* A few places in the bge.events docs mentioned bge.keys, when it should have been bge.events * Created two aliases to bge.events.RETKEY: ENTERKEY and RETURNKEY * ENTERKEY and RETURNKEY have been added to the docs and RETKEY marked as deprecated * Added an example of using bge.logic.keyboard to the bge.events docs
This commit is contained in:
@@ -2214,6 +2214,8 @@ PyObject* initGameKeys()
|
||||
KX_MACRO_addTypesToDict(d, ESCKEY, SCA_IInputDevice::KX_ESCKEY);
|
||||
KX_MACRO_addTypesToDict(d, TABKEY, SCA_IInputDevice::KX_TABKEY);
|
||||
KX_MACRO_addTypesToDict(d, RETKEY, SCA_IInputDevice::KX_RETKEY);
|
||||
KX_MACRO_addTypesToDict(d, ENTERKEY, SCA_IInputDevice::KX_RETKEY);
|
||||
KX_MACRO_addTypesToDict(d, RETURNKEY, SCA_IInputDevice::KX_RETKEY);
|
||||
KX_MACRO_addTypesToDict(d, SPACEKEY, SCA_IInputDevice::KX_SPACEKEY);
|
||||
KX_MACRO_addTypesToDict(d, LINEFEEDKEY, SCA_IInputDevice::KX_LINEFEEDKEY);
|
||||
KX_MACRO_addTypesToDict(d, BACKSPACEKEY, SCA_IInputDevice::KX_BACKSPACEKEY);
|
||||
|
||||
@@ -18,7 +18,7 @@ This module holds key constants for the SCA_KeyboardSensor.
|
||||
co = bge.logic.getCurrentController()
|
||||
# 'Keyboard' is a keyboard sensor
|
||||
sensor = co.sensors["Keyboard"]
|
||||
sensor.key = bge.keys.F1KEY
|
||||
sensor.key = bge.events.F1KEY
|
||||
|
||||
.. code-block:: python
|
||||
|
||||
@@ -30,17 +30,37 @@ This module holds key constants for the SCA_KeyboardSensor.
|
||||
sensor = co.sensors["Keyboard"]
|
||||
|
||||
for key,status in sensor.events:
|
||||
# key[0] == bge.keys.keycode, key[1] = status
|
||||
# key[0] == bge.events.keycode, key[1] = status
|
||||
if status == bge.logic.KX_INPUT_JUST_ACTIVATED:
|
||||
if key == bge.keys.WKEY:
|
||||
if key == bge.events.WKEY:
|
||||
# Activate Forward!
|
||||
if key == bge.keys.SKEY:
|
||||
if key == bge.events.SKEY:
|
||||
# Activate Backward!
|
||||
if key == bge.keys.AKEY:
|
||||
if key == bge.events.AKEY:
|
||||
# Activate Left!
|
||||
if key == bge.keys.DKEY:
|
||||
if key == bge.events.DKEY:
|
||||
# Activate Right!
|
||||
|
||||
.. code-block:: python
|
||||
|
||||
# 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 keyboard.events[bge.events.WKEY] == JUST_ACTIVATED:
|
||||
print("Activate Forward!")
|
||||
if keyboard.events[bge.events.SKEY] == JUST_ACTIVATED:
|
||||
print("Activate Backward!")
|
||||
if keyboard.events[bge.events.AKEY] == JUST_ACTIVATED:
|
||||
print("Activate Left!")
|
||||
if keyboard.events[bge.events.DKEY] == JUST_ACTIVATED:
|
||||
print("Activate Right!")
|
||||
|
||||
|
||||
*********
|
||||
Functions
|
||||
*********
|
||||
@@ -222,7 +242,9 @@ Other Keys
|
||||
.. data:: PERIODKEY
|
||||
.. data:: QUOTEKEY
|
||||
.. data:: RIGHTBRACKETKEY
|
||||
.. data:: RETKEY
|
||||
.. data:: RETKEY (Deprecated: use bge.events.ENTERKEY or bge.events.RETURNKEY)
|
||||
.. data:: ENTERKEY
|
||||
.. data:: RETURNKEY
|
||||
.. data:: SEMICOLONKEY
|
||||
.. data:: SLASHKEY
|
||||
.. data:: SPACEKEY
|
||||
|
||||
Reference in New Issue
Block a user