Runtime:hasEventSource()

Type Function
Object Runtime
Library none
Return value Boolean
Revision Release 2022.3683
Keywords runtime, hasEventSource
See also EventDispatcher:addEventListener()

Overview

Determines if the device is capable of providing events for a given event source such as "accelerometer" or "gyroscope".

This function returns true if the event source exists, meaning it is okay to call EventDispatcher:addEventListener() to handle its events.

It returns false if the event source does not exist. For example, if this returns false for "gyroscope" then this would indicate that the appropriate hardware was not found on the device.

Syntax

Runtime:hasEventSource( eventSourceName )
eventSourceName (required)

String. The name of the event source for which to check existence. The following values are valid:

  • "accelerometer"
  • "gyroscope"
  • "heading"
  • "inputDeviceStatus"
  • "key"
  • "location"
  • "mouse"
  • "multitouch"
  • "orientation"

Example

if Runtime:hasEventSource( "gyroscope" ) then
    Runtime:addEventListener( "gyroscope", myListener )
end