Blender Git Commit Log

Git Commits -> Revision 795b438

Revision 795b438 by Dalai Felinto (master)
April 17, 2010, 06:52 (GMT)
Patch #21789 - BGE Keyboard and Mouse Python types - by Mitchell Stokes(Moguri)
The patch exposes mouse and keyboard read-only properties in the GameLogic module
Also renames bge.keys to bge.events (* Note: name of bge submodules (logic, render, ...) may change before 2.5 final release [right Campbell?]).

"""
This patch adds two new types to the BGE:
SCA_PythonKeyboard
SCA_PythonMouse

These two types allow users to make use of the keyboard and mouse without the need for a keyboard or mouse sensor.

SCA_PythonKeyboard has an events property that acts just like SCA_KeyboardSensor.events.

SCA_PythonMouse also has an events property to check for mouse events. Further more it supports getting and setting normalized cursor position (from 0.0 to 1.0) with SCA_PythonMouse.position. The cursor can be shown/hidden using SCA_PythonMouse.visible.
"""

Its use is similar with current mouse and keyboard controllers. With the exception of mouse position being normalized and writable as well (replacing Rasterizer.setMousePosition).

Code Sample:
######
from bge import logic, events

mouse = logic.mouse
keyboard = logic.keyboard

for key,status in keyboard.events:
if status == logic.KX_INPUT_JUST_ACTIVATED:
if key == events.WKEY:
print(mouse.position)
# move_forward()

mouse.visible = True # turn cursor visible
mouse.position = 0.5,0.5 # centralize mouse - use tuple
######

* Important Note: mouse.position still will not work properly for Letterbox mode.
In order to fix letterboxing I may need to move the set x,y mouse function to inside the canvas code (to avoid duplicated code between mouse sensor and bge.logic.mouse). I'll leave this for another commit though.
Thanks Mitchell for the work on that.

Commit Details:

Full Hash: 795b438bf5565a87765edb880318b7e241714270
SVN Revision: 28240
Parent Commit: 6562e6a
Lines Changed: +498, -1

4 Added Paths:

/source/gameengine/GameLogic/SCA_PythonKeyboard.cpp (+115, -0) (View)
/source/gameengine/GameLogic/SCA_PythonKeyboard.h (+51, -0) (View)
/source/gameengine/GameLogic/SCA_PythonMouse.cpp (+185, -0) (View)
/source/gameengine/GameLogic/SCA_PythonMouse.h (+60, -0) (View)

9 Modified Paths:

/source/gameengine/BlenderRoutines/KX_BlenderCanvas.cpp (+2, -0) (Diff)
/source/gameengine/GamePlayer/ghost/GPG_Canvas.cpp (+2, -0) (Diff)
/source/gameengine/Ketsji/KX_KetsjiEngine.h (+2, -0) (Diff)
/source/gameengine/Ketsji/KX_PythonInit.cpp (+19, -1) (Diff)
/source/gameengine/Ketsji/KX_PythonInitTypes.cpp (+4, -0) (Diff)
/source/gameengine/PyDoc/GameKeys.py (+9, -0) (Diff)
/source/gameengine/PyDoc/GameLogic.py (+3, -0) (Diff)
/source/gameengine/PyDoc/GameTypes.py (+37, -0) (Diff)
/source/gameengine/Rasterizer/RAS_ICanvas.h (+9, -0) (Diff)
By: Miika HämäläinenLast update: Nov-07-2014 14:18MiikaHweb | 2003-2021