blender/source/gameengine/PyDoc
Dalai Felinto 795b438bf5 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.
2010-04-17 06:52:14 +00:00
..
API_intro.py PyAPI 2010-04-11 14:22:27 +00:00
bge_api_validate_py.txt Name attributes added since 2.48a more consistently. 2009-05-15 03:26:53 +00:00
epy_docgen.sh - Added an intro page for the BGE docs rather then using GameLogic 2009-05-20 01:11:56 +00:00
GameKeys.py Patch #21789 - BGE Keyboard and Mouse Python types - by Mitchell Stokes(Moguri) 2010-04-17 06:52:14 +00:00
GameLogic.py Patch #21789 - BGE Keyboard and Mouse Python types - by Mitchell Stokes(Moguri) 2010-04-17 06:52:14 +00:00
GameTypes.py Patch #21789 - BGE Keyboard and Mouse Python types - by Mitchell Stokes(Moguri) 2010-04-17 06:52:14 +00:00
how_to_build_win.txt BGE API DOC: a guide on how to build epydoc for windows 2010-03-30 06:37:44 +00:00
PhysicsConstraints.py BGE API_DOC: VideoTexture and PhysicsConstraints templates (need the functions to be filled with their description). 2010-01-10 19:35:42 +00:00
Rasterizer.py PyDoc updated for Rasterizer setEyeSeparation and setFocalLength + blenderplayer building again. 2010-01-07 05:23:54 +00:00
SConscript Better unix filesystem integration as documented here 2009-09-21 03:16:26 +00:00
VideoTexture.py VideoTexture: more PyDoc. 2010-03-28 20:15:45 +00:00