2010-05-17 19:52:25 +00:00
|
|
|
|
2011-07-30 23:16:22 +00:00
|
|
|
Game Keys (bge.events)
|
2011-07-31 03:15:37 +00:00
|
|
|
======================
|
2010-05-17 19:52:25 +00:00
|
|
|
|
2010-06-03 14:26:38 +00:00
|
|
|
*****
|
|
|
|
Intro
|
|
|
|
*****
|
|
|
|
|
2010-05-17 19:52:25 +00:00
|
|
|
This module holds key constants for the SCA_KeyboardSensor.
|
|
|
|
|
|
|
|
.. module:: bge.events
|
|
|
|
|
|
|
|
.. code-block:: python
|
|
|
|
|
|
|
|
# Set a connected keyboard sensor to accept F1
|
|
|
|
import bge
|
2014-04-01 05:20:03 +00:00
|
|
|
|
2010-05-17 19:52:25 +00:00
|
|
|
co = bge.logic.getCurrentController()
|
|
|
|
# 'Keyboard' is a keyboard sensor
|
|
|
|
sensor = co.sensors["Keyboard"]
|
2010-10-05 05:44:15 +00:00
|
|
|
sensor.key = bge.events.F1KEY
|
2010-05-17 19:52:25 +00:00
|
|
|
|
|
|
|
.. code-block:: python
|
|
|
|
|
|
|
|
# Do the all keys thing
|
|
|
|
import bge
|
2014-04-01 05:20:03 +00:00
|
|
|
|
2010-05-17 19:52:25 +00:00
|
|
|
co = bge.logic.getCurrentController()
|
|
|
|
# 'Keyboard' is a keyboard sensor
|
|
|
|
sensor = co.sensors["Keyboard"]
|
|
|
|
|
|
|
|
for key,status in sensor.events:
|
2010-10-05 05:44:15 +00:00
|
|
|
# key[0] == bge.events.keycode, key[1] = status
|
2010-05-17 19:52:25 +00:00
|
|
|
if status == bge.logic.KX_INPUT_JUST_ACTIVATED:
|
2010-10-05 05:44:15 +00:00
|
|
|
if key == bge.events.WKEY:
|
2010-05-17 19:52:25 +00:00
|
|
|
# Activate Forward!
|
2010-10-05 05:44:15 +00:00
|
|
|
if key == bge.events.SKEY:
|
2010-05-17 19:52:25 +00:00
|
|
|
# Activate Backward!
|
2010-10-05 05:44:15 +00:00
|
|
|
if key == bge.events.AKEY:
|
2010-05-17 19:52:25 +00:00
|
|
|
# Activate Left!
|
2010-10-05 05:44:15 +00:00
|
|
|
if key == bge.events.DKEY:
|
2010-05-17 19:52:25 +00:00
|
|
|
# Activate Right!
|
|
|
|
|
2010-10-05 05:44:15 +00:00
|
|
|
.. code-block:: python
|
|
|
|
|
|
|
|
# The all keys thing without a keyboard sensor (but you will
|
|
|
|
# need an always sensor with pulse mode on)
|
|
|
|
import bge
|
2014-04-01 05:20:03 +00:00
|
|
|
|
2010-10-05 05:44:15 +00:00
|
|
|
# Just shortening names here
|
|
|
|
keyboard = bge.logic.keyboard
|
|
|
|
JUST_ACTIVATED = bge.logic.KX_INPUT_JUST_ACTIVATED
|
2014-04-01 05:20:03 +00:00
|
|
|
|
2010-10-05 05:44:15 +00:00
|
|
|
if keyboard.events[bge.events.WKEY] == JUST_ACTIVATED:
|
|
|
|
print("Activate Forward!")
|
|
|
|
if keyboard.events[bge.events.SKEY] == JUST_ACTIVATED:
|
2014-04-01 05:20:03 +00:00
|
|
|
print("Activate Backward!")
|
2010-10-05 05:44:15 +00:00
|
|
|
if keyboard.events[bge.events.AKEY] == JUST_ACTIVATED:
|
2014-04-01 05:20:03 +00:00
|
|
|
print("Activate Left!")
|
2010-10-05 05:44:15 +00:00
|
|
|
if keyboard.events[bge.events.DKEY] == JUST_ACTIVATED:
|
|
|
|
print("Activate Right!")
|
2014-04-01 05:20:03 +00:00
|
|
|
|
2010-10-05 05:44:15 +00:00
|
|
|
|
2010-06-03 14:26:38 +00:00
|
|
|
*********
|
|
|
|
Functions
|
|
|
|
*********
|
|
|
|
|
2010-05-17 19:52:25 +00:00
|
|
|
.. function:: EventToString(event)
|
|
|
|
|
|
|
|
Return the string name of a key event. Will raise a ValueError error if its invalid.
|
|
|
|
|
2013-01-28 06:39:23 +00:00
|
|
|
:arg event: key event constant from :mod:`bge.events` or the keyboard sensor.
|
2010-05-17 19:52:25 +00:00
|
|
|
:type event: int
|
|
|
|
:rtype: string
|
2014-04-01 05:20:03 +00:00
|
|
|
|
2010-05-17 19:52:25 +00:00
|
|
|
.. function:: EventToCharacter(event, shift)
|
|
|
|
|
|
|
|
Return the string name of a key event. Returns an empty string if the event cant be represented as a character.
|
2014-04-01 05:20:03 +00:00
|
|
|
|
2010-05-17 19:52:25 +00:00
|
|
|
:type event: int
|
2013-01-28 06:39:23 +00:00
|
|
|
:arg event: key event constant from :mod:`bge.events` or the keyboard sensor.
|
2010-05-17 19:52:25 +00:00
|
|
|
:type shift: bool
|
|
|
|
:arg shift: set to true if shift is held.
|
|
|
|
:rtype: string
|
|
|
|
|
2010-06-03 14:26:38 +00:00
|
|
|
****************
|
|
|
|
Keys (Constants)
|
|
|
|
****************
|
|
|
|
|
|
|
|
.. _mouse-keys:
|
|
|
|
|
|
|
|
==========
|
|
|
|
Mouse Keys
|
|
|
|
==========
|
|
|
|
|
|
|
|
.. data:: LEFTMOUSE
|
|
|
|
.. data:: MIDDLEMOUSE
|
|
|
|
.. data:: RIGHTMOUSE
|
|
|
|
.. data:: WHEELUPMOUSE
|
|
|
|
.. data:: WHEELDOWNMOUSE
|
|
|
|
.. data:: MOUSEX
|
|
|
|
.. data:: MOUSEY
|
|
|
|
|
2010-06-07 23:50:43 +00:00
|
|
|
.. _keyboard-keys:
|
|
|
|
|
2010-06-03 14:26:38 +00:00
|
|
|
=============
|
|
|
|
Keyboard Keys
|
|
|
|
=============
|
2010-05-17 19:52:25 +00:00
|
|
|
|
2010-06-03 14:26:38 +00:00
|
|
|
-------------
|
|
|
|
Alphabet keys
|
|
|
|
-------------
|
2010-05-17 19:52:25 +00:00
|
|
|
|
|
|
|
.. data:: AKEY
|
|
|
|
.. data:: BKEY
|
|
|
|
.. data:: CKEY
|
|
|
|
.. data:: DKEY
|
|
|
|
.. data:: EKEY
|
|
|
|
.. data:: FKEY
|
|
|
|
.. data:: GKEY
|
|
|
|
.. data:: HKEY
|
|
|
|
.. data:: IKEY
|
|
|
|
.. data:: JKEY
|
|
|
|
.. data:: KKEY
|
|
|
|
.. data:: LKEY
|
|
|
|
.. data:: MKEY
|
|
|
|
.. data:: NKEY
|
|
|
|
.. data:: OKEY
|
|
|
|
.. data:: PKEY
|
|
|
|
.. data:: QKEY
|
|
|
|
.. data:: RKEY
|
|
|
|
.. data:: SKEY
|
|
|
|
.. data:: TKEY
|
|
|
|
.. data:: UKEY
|
|
|
|
.. data:: VKEY
|
|
|
|
.. data:: WKEY
|
|
|
|
.. data:: XKEY
|
|
|
|
.. data:: YKEY
|
|
|
|
.. data:: ZKEY
|
|
|
|
|
2010-06-03 14:26:38 +00:00
|
|
|
-----------
|
|
|
|
Number keys
|
|
|
|
-----------
|
2010-05-17 19:52:25 +00:00
|
|
|
|
|
|
|
.. data:: ZEROKEY
|
|
|
|
.. data:: ONEKEY
|
|
|
|
.. data:: TWOKEY
|
|
|
|
.. data:: THREEKEY
|
|
|
|
.. data:: FOURKEY
|
|
|
|
.. data:: FIVEKEY
|
|
|
|
.. data:: SIXKEY
|
|
|
|
.. data:: SEVENKEY
|
|
|
|
.. data:: EIGHTKEY
|
|
|
|
.. data:: NINEKEY
|
|
|
|
|
2010-06-03 14:26:38 +00:00
|
|
|
--------------
|
|
|
|
Modifiers Keys
|
|
|
|
--------------
|
2010-05-17 19:52:25 +00:00
|
|
|
|
|
|
|
.. data:: CAPSLOCKKEY
|
|
|
|
.. data:: LEFTCTRLKEY
|
|
|
|
.. data:: LEFTALTKEY
|
|
|
|
.. data:: RIGHTALTKEY
|
|
|
|
.. data:: RIGHTCTRLKEY
|
|
|
|
.. data:: RIGHTSHIFTKEY
|
|
|
|
.. data:: LEFTSHIFTKEY
|
|
|
|
|
2010-06-03 14:26:38 +00:00
|
|
|
----------
|
|
|
|
Arrow Keys
|
|
|
|
----------
|
2010-05-17 19:52:25 +00:00
|
|
|
|
|
|
|
.. data:: LEFTARROWKEY
|
|
|
|
.. data:: DOWNARROWKEY
|
|
|
|
.. data:: RIGHTARROWKEY
|
|
|
|
.. data:: UPARROWKEY
|
|
|
|
|
2010-06-03 14:26:38 +00:00
|
|
|
--------------
|
|
|
|
Numberpad Keys
|
|
|
|
--------------
|
2010-05-17 19:52:25 +00:00
|
|
|
|
|
|
|
.. data:: PAD0
|
|
|
|
.. data:: PAD1
|
|
|
|
.. data:: PAD2
|
|
|
|
.. data:: PAD3
|
|
|
|
.. data:: PAD4
|
|
|
|
.. data:: PAD5
|
|
|
|
.. data:: PAD6
|
|
|
|
.. data:: PAD7
|
|
|
|
.. data:: PAD8
|
|
|
|
.. data:: PAD9
|
|
|
|
.. data:: PADPERIOD
|
|
|
|
.. data:: PADSLASHKEY
|
|
|
|
.. data:: PADASTERKEY
|
|
|
|
.. data:: PADMINUS
|
|
|
|
.. data:: PADENTER
|
|
|
|
.. data:: PADPLUSKEY
|
|
|
|
|
2010-06-03 14:26:38 +00:00
|
|
|
-------------
|
|
|
|
Function Keys
|
|
|
|
-------------
|
2010-05-17 19:52:25 +00:00
|
|
|
|
|
|
|
.. data:: F1KEY
|
|
|
|
.. data:: F2KEY
|
|
|
|
.. data:: F3KEY
|
|
|
|
.. data:: F4KEY
|
|
|
|
.. data:: F5KEY
|
|
|
|
.. data:: F6KEY
|
|
|
|
.. data:: F7KEY
|
|
|
|
.. data:: F8KEY
|
|
|
|
.. data:: F9KEY
|
|
|
|
.. data:: F10KEY
|
|
|
|
.. data:: F11KEY
|
|
|
|
.. data:: F12KEY
|
|
|
|
.. data:: F13KEY
|
|
|
|
.. data:: F14KEY
|
|
|
|
.. data:: F15KEY
|
|
|
|
.. data:: F16KEY
|
|
|
|
.. data:: F17KEY
|
|
|
|
.. data:: F18KEY
|
|
|
|
.. data:: F19KEY
|
|
|
|
|
2010-06-03 14:26:38 +00:00
|
|
|
----------
|
|
|
|
Other Keys
|
|
|
|
----------
|
2010-05-17 19:52:25 +00:00
|
|
|
|
|
|
|
.. data:: ACCENTGRAVEKEY
|
|
|
|
.. data:: BACKSLASHKEY
|
|
|
|
.. data:: BACKSPACEKEY
|
|
|
|
.. data:: COMMAKEY
|
|
|
|
.. data:: DELKEY
|
|
|
|
.. data:: ENDKEY
|
|
|
|
.. data:: EQUALKEY
|
|
|
|
.. data:: ESCKEY
|
|
|
|
.. data:: HOMEKEY
|
|
|
|
.. data:: INSERTKEY
|
|
|
|
.. data:: LEFTBRACKETKEY
|
|
|
|
.. data:: LINEFEEDKEY
|
|
|
|
.. data:: MINUSKEY
|
|
|
|
.. data:: PAGEDOWNKEY
|
|
|
|
.. data:: PAGEUPKEY
|
|
|
|
.. data:: PAUSEKEY
|
|
|
|
.. data:: PERIODKEY
|
|
|
|
.. data:: QUOTEKEY
|
|
|
|
.. data:: RIGHTBRACKETKEY
|
2010-10-06 00:36:12 +00:00
|
|
|
.. data:: RETKEY (Deprecated: use bge.events.ENTERKEY)
|
2010-10-05 05:44:15 +00:00
|
|
|
.. data:: ENTERKEY
|
2010-05-17 19:52:25 +00:00
|
|
|
.. data:: SEMICOLONKEY
|
|
|
|
.. data:: SLASHKEY
|
|
|
|
.. data:: SPACEKEY
|
|
|
|
.. data:: TABKEY
|