Skip to content
Shi Yin edited this page Sep 21, 2013 · 20 revisions

class Event

Last revision: ver. 4.2-alpha6 - 26 August 2013

[[module omega | Python-Reference#module-omega]] wraps omicron::Event

Encapsulates information about input events. Input events are explained in more detail here. This class is used within the context of an event handler function, registered through the setEventFunction call. The EventType, EventFlags, EventExtraDataType, ServiceType are together with the event class.

Methods

Method(s) Description
isKeyDown(int key), isKeyUp(int key) Check if a key has been prssed / depressed in this event. Use this for keyboard-generated events. key should be a keyboard scan-code. Convert between characters and scan-codes using the python ord function: isKeyDown(ord('A'))
isButtonDown(button), isButtonUp(button)
bool isFlagSet(button) Check is a button or key is marked as pressed in this event.
getAxis(index) Gets the value for the specified axis (if available) Non available axes return 0 by default.
getSourceId()
getType()
getServiceType()
getPosition(), getOrientation()
isProcessed() Returns True if this event has already been handled somewhere else
setProcessed() Marks this event as processed. When an event is marked as processed, it will not be sent to engine modules with priority lower than the module that marked the event as processed. Python scripts always run with normal priority, so setting an event as processed will not forward it to modules with Low or Lowest priority. To see what modules are active in your application and what is their priority, type printModules() in the console.

Global Functions

[[Event]] getEvent()

Returns the event currenty being processed. Should be used only inside an event handler function.

getRayFromEvent([[Event]] evt)

Returns a 3D ray from events that support ray generation. Pointer, Wand and Mocap events all support the generation of 3D rays into the scene. A typical use of rays is object picking. (see querySceneRay) The function returns a tuple containing three values:

  • A boolean, se tto true when ray generation was sucessfull
  • A Vector3 containing the ray origin
  • A Vector3containing the ray direction

getRayFromPoint(float x, float y)

Returns a ray from a 2D point on the screen plane. This method works for tiled displays as long as they provide a planar mapping of the display geometry (PlanarDisplayConfig and CylindricalDisplayConfig work. CustomDisplayConfig does not). The function returns a tuple containing three values:

  • A boolean, se tto true when ray generation was sucessfull
  • A Vector3 containing the ray origin
  • A Vector3containing the ray direction

Event types

The method getType() returns a value from the EventType enumeration. The EventType enumeration contains the following values: Select, Toggle, ChangeValue, Update, Move, Down, Up, Trace, Connect, Untrace, Disconnect, Click, Zoom, Split, Rotate, Null

For more information about event types read the Event reference page of the omicron SDK

Event flags

The methods isKeyDown(), isKeyUp(), isButtonDown(), isButtonUp() return a value from the EventFlags enumeration. The EventFlags enumeration contains the following values: Left, Middle, Right, Button1, Button2, Button3, Button4, Button5, Button6, Button7, SpecialButton1, SpecialButton2, SpecialButton3, Ctrl, Alt, Shift, ButtonDown, ButtonUp, ButtonLeft, ButtonRight, Processed, User

For more information about event flags read the Event reference page of the omicron SDK

Event service types

The method getServiceType() returns a value from the ServiceType enumeration. The ServiceType enumeration contains the following values: Pointer, Mocap, Keyboard, Controller, Ui, Generic, Brain, Wand, Audio

For more information about event service types read the Event reference page of the omicron SDK

Example: PS3 Move Controller Button Mapping

Example Scripts

Button handling

	def handleEvent():
		e = getEvent()
		print(e.getPosition())
		if(e.isButtonDown(EventFlags.ButtonLeft)): 
			print("Left button pressed")
		if(e.isButtonDown(EventFlags.ButtonUp)): 
			print("Up button pressed")
			
	setEventFunction(handleEvent)

Axis handling

def onEvent():
     e = getEvent()
     if(e.getServiceType() = ServiceType.Wand):
          print("Wand analog X : " + str(e.getAxis(0)))
          
setEventFunction(onEvent)

Key Handling

def onEvent():
	e = getEvent()
	if ( type == ServiceType.Keyboard ): 
		# DO NOT pass the character directly to isKeyDown, use ord().
		# The reason is that the isKeyDown function needs the key scan code,
		# not the character (since keys like Shift, Alt, etc do not have an 
		# ASCII character). ord() does the conversion for you.
		if ( e.isKeyDown(ord('a'))): 
			print("key 'a' pressed")

setEventFunction(onEvent)
Clone this wiki locally