blender/source
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
..
blender PThreads "fix" for CMake / MSVC 2010-04-16 23:58:12 +00:00
blenderplayer BGE: stubs update (bplayer) 2010-04-12 23:02:14 +00:00
creator Merge various small changes from render branch: 2010-04-15 10:28:32 +00:00
darwin OS X Makefiles: 2010-01-03 20:35:13 +00:00
gameengine Patch #21789 - BGE Keyboard and Mouse Python types - by Mitchell Stokes(Moguri) 2010-04-17 06:52:14 +00:00
icons missed a file in previous crosscompiling related commits 2010-02-18 06:53:10 +00:00
kernel correct fsf address 2010-02-12 13:34:04 +00:00
CMakeLists.txt correct fsf address 2010-02-12 13:34:04 +00:00
Makefile Modifiers moved, adjust accordingly. 2010-04-12 01:23:55 +00:00
nan_compile.mk Fix #21374: OS X Makefiles missed optimization flags in 2.5 since at least 2010-03-05 14:29:48 +00:00
nan_definitions.mk OSX buildscripts update following ffmpeg precompiled libs update 2010-02-22 16:34:27 +00:00
nan_link.mk correct fsf address 2010-02-12 13:34:04 +00:00
nan_subdirs.mk correct fsf address 2010-02-12 13:34:04 +00:00
nan_warn.mk correct fsf address 2010-02-12 13:34:04 +00:00
SConscript this restores building on mingw with Collada support, also it restores cross compiling, thanks to Sergey Sharybin for the patch. Note that the icons for linux cross might not be committed here, if not i'll add them in another commit 2010-02-01 18:39:41 +00:00