Skip to content
Alessandro Febretti edited this page Jan 18, 2015 · 20 revisions

class Event

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

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 pressed / 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.
int getServiceId() Gets the identifier of the service that generated this event.
int getUserId() Gets the identifier of the user associated with this event.
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. The function returns a tuple containing three values:

  • A boolean, set to true when ray generation was successful
  • A Vector3 containing the ray origin
  • A Vector3 containing 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)

Keeping Track of Button state

I know I can use the event isButtonDown and isButtonUp to check for button presses and releases, but what if I want to check the button state for my wand / game controller / mouse?

If you want your code to work both with a mouse and a wand, the best way is to set a flag and process it in the update function:

button1Pressed = False

def onEvent(e):
   if(e.isButtonDown(Event.Button1)): button1Pressed = True
   else if(e.isButtonUp(Event.Button1)): button1Pressed = False


def onUpdate(frame, time, dt):
   if(button1Pressed) print("Button 1 is currently pressed")

You can also use the isFlagSet method of an event to see if a button or key is currently in the pressed state

def onEvent(e):
  if(e.isFlagSet(Event.Button1)): print("button1Pressed")

But this more device-dependent because it depends on the frequency at which the input devices send out events. The best way of doing this is the first one.

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)

Mouse-based Manipulation

https://gist.github.com/febret/9ca350a86657cfa97d48

Clone this wiki locally