{"metadata":{"image":[],"title":"","description":""},"api":{"url":"","auth":"required","params":[],"results":{"codes":[]},"settings":""},"next":{"description":"","pages":[]},"title":"VRTK_ControllerEvents","type":"basic","slug":"controllerevents","excerpt":"","body":"## Overview\n\nThe Controller Events script deals with events that the game controller is sending out.\n\nThe Controller Events script is attached to a Controller object within the `[CameraRig]` prefab and provides event listeners for every button press on the controller (excluding the System Menu button as this cannot be overriden and is always used by Steam).\n\nWhen a controller button is pressed, the script emits an event to denote that the button has been pressed which allows other scripts to listen for this event without needing to implement any controller logic. When a controller button is released, the script also emits an event denoting that the button has been released.\n\nThe script also has a public boolean pressed state for the buttons to allow the script to be queried by other scripts to check if a button is being held down.\n\n## Inspector Parameters\n\n  * **Pointer Toggle Button:** The button to use for the action of turning a laser pointer on/off.\n  * **Pointer Set Button:** The button to use for the action of setting a destination marker from the cursor position of the pointer.\n  * **Grab Toggle Button:** The button to use for the action of grabbing game objects.\n  * **Use Toggle Button:** The button to use for the action of using game objects.\n  * **UI Click Button:** The button to use for the action of clicking a UI element.\n  * **Menu Toggle Button:** The button to use for the action of bringing up an in-game menu.\n  * **Axis Fidelity:** The amount of fidelity in the changes on the axis, which is defaulted to 1. Any number higher than 2 will probably give too sensitive results.\n\n## Class Variables\n\n  * `public bool triggerPressed` - This will be true if the trigger is squeezed about half way in.\n  * `public bool triggerTouched` - This will be true if the trigger is squeezed a small amount.\n  * `public bool triggerHairlinePressed` - This will be true if the trigger is squeezed a small amount more from any previous squeeze on the trigger.\n  * `public bool triggerClicked` - This will be true if the trigger is squeezed all the way until it clicks.\n  * `public bool triggerAxisChanged` - This will be true if the trigger has been squeezed more or less.\n  * `public bool applicationMenuPressed` - This will be true if the application menu is held down.\n  * `public bool touchpadPressed` - This will be true if the touchpad is held down.\n  * `public bool touchpadTouched` - This will be true if the touchpad is being touched.\n  * `public bool touchpadAxisChanged` - This will be true if the touchpad touch position has changed.\n  * `public bool gripPressed` - This will be true if the grip is held down.\n  * `public bool pointerPressed` - This will be true if the button aliased to the pointer is held down.\n  * `public bool grabPressed` - This will be true if the button aliased to the grab is held down.\n  * `public bool usePressed` - This will be true if the button aliased to the use is held down.\n  * `public bool uiClickPressed` - This will be true if the button aliased to the UI click is held down.\n  * `public bool menuPressed` - This will be true if the button aliased to the application menu is held down.\n\n## Class Events\n\n  * `TriggerPressed` - Emitted when the trigger is squeezed about half way in.\n  * `TriggerReleased` - Emitted when the trigger is released under half way.\n  * `TriggerTouchStart` - Emitted when the trigger is squeezed a small amount.\n  * `TriggerTouchEnd` - Emitted when the trigger is no longer being squeezed at all.\n  * `TriggerHairlineStart` - Emitted when the trigger is squeezed past the current hairline threshold.\n  * `TriggerHairlineEnd` - Emitted when the trigger is released past the current hairline threshold.\n  * `TriggerClicked` - Emitted when the trigger is squeezed all the way until it clicks.\n  * `TriggerUnclicked` - Emitted when the trigger is no longer being held all the way down.\n  * `TriggerAxisChanged` - Emitted when the amount of squeeze on the trigger changes.\n  * `ApplicationMenuPressed` - Emitted when the application menu button is pressed.\n  * `ApplicationMenuReleased` - Emitted when the application menu button is released.\n  * `GripPressed` - Emitted when the grip button is pressed.\n  * `GripReleased` - Emitted when the grip button is released.\n  * `TouchpadPressed` - Emitted when the touchpad is pressed (to the point of hearing a click).\n  * `TouchpadReleased` - Emitted when the touchpad has been released after a pressed state.\n  * `TouchpadTouchStart` - Emitted when the touchpad is touched (without pressing down to click).\n  * `TouchpadTouchEnd` - Emitted when the touchpad is no longer being touched.\n  * `TouchpadAxisChanged` - Emitted when the touchpad is being touched in a different location.\n  * `AliasPointerOn` - Emitted when the pointer toggle alias button is pressed.\n  * `AliasPointerOff` - Emitted when the pointer toggle alias button is released.\n  * `AliasPointerSet` - Emitted when the pointer set alias button is released.\n  * `AliasGrabOn` - Emitted when the grab toggle alias button is pressed.\n  * `AliasGrabOff` - Emitted when the grab toggle alias button is released.\n  * `AliasUseOn` - Emitted when the use toggle alias button is pressed.\n  * `AliasUseOff` - Emitted when the use toggle alias button is released.\n  * `AliasMenuOn` - Emitted when the menu toggle alias button is pressed.\n  * `AliasMenuOff` - Emitted when the menu toggle alias button is released.\n  * `AliasUIClickOn` - Emitted when the UI click alias button is pressed.\n  * `AliasUIClickOff` - Emitted when the UI click alias button is released.\n\n### Event Payload\n\n  * `uint controllerIndex` - The index of the controller that was used.\n  * `float buttonPressure` - The amount of pressure being applied to the button pressed. `0f` to `1f`.\n  * `Vector2 touchpadAxis` - The position the touchpad is touched at. `(0,0)` to `(1,1)`.\n  * `float touchpadAngle` - The rotational position the touchpad is being touched at, 0 being top, 180 being bottom and all other angles accordingly. `0f` to `360f`.\n\n## Class Methods\n\n### GetVelocity/0\n\n  > `public Vector3 GetVelocity()`\n\n  * Parameters\n   * _none_\n  * Returns\n   * `Vector3` - A 3 dimensional vector containing the current real world physical controller velocity.\n\nThe GetVelocity method is useful for getting the current velocity of the physical game controller. This can be useful to determine the speed at which the controller is being swung or the direction it is being moved in.\n\n### GetAngularVelocity/0\n\n  > `public Vector3 GetAngularVelocity()`\n\n  * Parameters\n   * _none_\n  * Returns\n   * `Vector3` - A 3 dimensional vector containing the current real world physical controller angular (rotational) velocity.\n\nThe GetAngularVelocity method is useful for getting the current rotational velocity of the phyiscal game controller. This can be useful for determining which way the controller is being rotated and at what speed the rotation is occuring.\n\n### GetTouchpadAxis/0\n\n  > `public Vector2 GetTouchpadAxis()`\n\n  * Parameters\n   * _none_\n  * Returns\n   * `Vector2` - A 2 dimensional vector containing the x and y position of where the touchpad is being touched. `(0,0)` to `(1,1)`.\n\nThe GetTouchpadAxis method returns the coordinates of where the touchpad is being touched and can be used for directional input via the touchpad. The `x` value is the horizontal touch plane and the `y` value is the vertical touch plane.\n\n### GetTouchpadAxisAngle/0\n\n  > `public float GetTouchpadAxisAngle()`\n\n  * Parameters\n   * _none_\n  * Returns\n   * `float` - A float representing the angle of where the touchpad is being touched. `0f` to `360f`.\n\nThe GetTouchpadAxisAngle method returns the angle of where the touchpad is currently being touched with the top of the touchpad being 0 degrees and the bottom of the touchpad being 180 degrees.\n\n### GetTriggerAxis/0\n\n  > `public float GetTriggerAxis()`\n\n  * Parameters\n   * _none_\n  * Returns\n   * `float` - A float representing the amount of squeeze that is being applied to the trigger. `0f` to `1f`.\n\nThe GetTriggerAxis method returns a float that represents how much the trigger is being squeezed. This can be useful for using the trigger axis to perform high fidelity tasks or only activating the trigger press once it has exceeded a given press threshold.\n\n### GetHairTriggerDelta/0\n\n  > `public float GetHairTriggerDelta()`\n\n  * Parameters\n   * _none_\n  * Returns\n   * `float` - A float representing the difference in the trigger pressure from the hairline threshold start to current position.\n\nThe GetHairTriggerDelta method returns a float representing the difference in how much the trigger is being pressed in relation to the hairline threshold start.\n\n### AnyButtonPressed/0\n\n  > `public bool AnyButtonPressed()`\n\n  * Parameters\n   * _none_\n  * Returns\n   * `bool` - Is true if any of the controller buttons are currently being pressed.\n\nThe AnyButtonPressed method returns true if any of the controller buttons are being pressed and this can be useful to determine if an action can be taken whilst the user is using the controller.\n\n## Example\n\n`SteamVR_Unity_Toolkit/Examples/002_Controller_Events` shows how the events are utilised and listened to. The accompanying example script can be viewed in `SteamVR_Unity_Toolkit/Examples/Resources/Scripts/VRTK_ControllerEvents_ListenerExample.cs`.","updates":[],"order":0,"isReference":false,"hidden":false,"sync_unique":"","link_url":"","link_external":false,"_id":"579e3ddcb0baa40e00a5e9f4","user":"571fa519db52d01700f5cf3d","parentDoc":null,"project":"571fa55ca0acd42000af9545","__v":0,"category":{"sync":{"isSync":false,"url":""},"pages":[],"title":"Scripts","slug":"scripts","order":3,"from_sync":false,"reference":false,"_id":"579e3b5d4c4ab40e00b494b8","__v":0,"createdAt":"2016-07-31T17:54:37.121Z","project":"571fa55ca0acd42000af9545","version":"579e29218cc49e0e00dea8ac"},"createdAt":"2016-07-31T18:05:16.726Z","githubsync":"","version":{"version":"2.1.0","version_clean":"2.1.0","codename":"","is_stable":false,"is_beta":false,"is_hidden":false,"is_deprecated":true,"categories":["579e29218cc49e0e00dea8ad","579e298f8cc49e0e00dea8af","579e2da1f8b52d0e0043fd0d","579e3b5d4c4ab40e00b494b8","579e3b624c4ab40e00b494b9","579f6fbd4f0dab32004014fb","579f6fc78d24193600b63c44"],"_id":"579e29218cc49e0e00dea8ac","__v":7,"project":"571fa55ca0acd42000af9545","createdAt":"2016-07-31T16:36:49.119Z","releaseDate":"2016-07-31T16:36:49.119Z"}}

VRTK_ControllerEvents


## Overview The Controller Events script deals with events that the game controller is sending out. The Controller Events script is attached to a Controller object within the `[CameraRig]` prefab and provides event listeners for every button press on the controller (excluding the System Menu button as this cannot be overriden and is always used by Steam). When a controller button is pressed, the script emits an event to denote that the button has been pressed which allows other scripts to listen for this event without needing to implement any controller logic. When a controller button is released, the script also emits an event denoting that the button has been released. The script also has a public boolean pressed state for the buttons to allow the script to be queried by other scripts to check if a button is being held down. ## Inspector Parameters * **Pointer Toggle Button:** The button to use for the action of turning a laser pointer on/off. * **Pointer Set Button:** The button to use for the action of setting a destination marker from the cursor position of the pointer. * **Grab Toggle Button:** The button to use for the action of grabbing game objects. * **Use Toggle Button:** The button to use for the action of using game objects. * **UI Click Button:** The button to use for the action of clicking a UI element. * **Menu Toggle Button:** The button to use for the action of bringing up an in-game menu. * **Axis Fidelity:** The amount of fidelity in the changes on the axis, which is defaulted to 1. Any number higher than 2 will probably give too sensitive results. ## Class Variables * `public bool triggerPressed` - This will be true if the trigger is squeezed about half way in. * `public bool triggerTouched` - This will be true if the trigger is squeezed a small amount. * `public bool triggerHairlinePressed` - This will be true if the trigger is squeezed a small amount more from any previous squeeze on the trigger. * `public bool triggerClicked` - This will be true if the trigger is squeezed all the way until it clicks. * `public bool triggerAxisChanged` - This will be true if the trigger has been squeezed more or less. * `public bool applicationMenuPressed` - This will be true if the application menu is held down. * `public bool touchpadPressed` - This will be true if the touchpad is held down. * `public bool touchpadTouched` - This will be true if the touchpad is being touched. * `public bool touchpadAxisChanged` - This will be true if the touchpad touch position has changed. * `public bool gripPressed` - This will be true if the grip is held down. * `public bool pointerPressed` - This will be true if the button aliased to the pointer is held down. * `public bool grabPressed` - This will be true if the button aliased to the grab is held down. * `public bool usePressed` - This will be true if the button aliased to the use is held down. * `public bool uiClickPressed` - This will be true if the button aliased to the UI click is held down. * `public bool menuPressed` - This will be true if the button aliased to the application menu is held down. ## Class Events * `TriggerPressed` - Emitted when the trigger is squeezed about half way in. * `TriggerReleased` - Emitted when the trigger is released under half way. * `TriggerTouchStart` - Emitted when the trigger is squeezed a small amount. * `TriggerTouchEnd` - Emitted when the trigger is no longer being squeezed at all. * `TriggerHairlineStart` - Emitted when the trigger is squeezed past the current hairline threshold. * `TriggerHairlineEnd` - Emitted when the trigger is released past the current hairline threshold. * `TriggerClicked` - Emitted when the trigger is squeezed all the way until it clicks. * `TriggerUnclicked` - Emitted when the trigger is no longer being held all the way down. * `TriggerAxisChanged` - Emitted when the amount of squeeze on the trigger changes. * `ApplicationMenuPressed` - Emitted when the application menu button is pressed. * `ApplicationMenuReleased` - Emitted when the application menu button is released. * `GripPressed` - Emitted when the grip button is pressed. * `GripReleased` - Emitted when the grip button is released. * `TouchpadPressed` - Emitted when the touchpad is pressed (to the point of hearing a click). * `TouchpadReleased` - Emitted when the touchpad has been released after a pressed state. * `TouchpadTouchStart` - Emitted when the touchpad is touched (without pressing down to click). * `TouchpadTouchEnd` - Emitted when the touchpad is no longer being touched. * `TouchpadAxisChanged` - Emitted when the touchpad is being touched in a different location. * `AliasPointerOn` - Emitted when the pointer toggle alias button is pressed. * `AliasPointerOff` - Emitted when the pointer toggle alias button is released. * `AliasPointerSet` - Emitted when the pointer set alias button is released. * `AliasGrabOn` - Emitted when the grab toggle alias button is pressed. * `AliasGrabOff` - Emitted when the grab toggle alias button is released. * `AliasUseOn` - Emitted when the use toggle alias button is pressed. * `AliasUseOff` - Emitted when the use toggle alias button is released. * `AliasMenuOn` - Emitted when the menu toggle alias button is pressed. * `AliasMenuOff` - Emitted when the menu toggle alias button is released. * `AliasUIClickOn` - Emitted when the UI click alias button is pressed. * `AliasUIClickOff` - Emitted when the UI click alias button is released. ### Event Payload * `uint controllerIndex` - The index of the controller that was used. * `float buttonPressure` - The amount of pressure being applied to the button pressed. `0f` to `1f`. * `Vector2 touchpadAxis` - The position the touchpad is touched at. `(0,0)` to `(1,1)`. * `float touchpadAngle` - The rotational position the touchpad is being touched at, 0 being top, 180 being bottom and all other angles accordingly. `0f` to `360f`. ## Class Methods ### GetVelocity/0 > `public Vector3 GetVelocity()` * Parameters * _none_ * Returns * `Vector3` - A 3 dimensional vector containing the current real world physical controller velocity. The GetVelocity method is useful for getting the current velocity of the physical game controller. This can be useful to determine the speed at which the controller is being swung or the direction it is being moved in. ### GetAngularVelocity/0 > `public Vector3 GetAngularVelocity()` * Parameters * _none_ * Returns * `Vector3` - A 3 dimensional vector containing the current real world physical controller angular (rotational) velocity. The GetAngularVelocity method is useful for getting the current rotational velocity of the phyiscal game controller. This can be useful for determining which way the controller is being rotated and at what speed the rotation is occuring. ### GetTouchpadAxis/0 > `public Vector2 GetTouchpadAxis()` * Parameters * _none_ * Returns * `Vector2` - A 2 dimensional vector containing the x and y position of where the touchpad is being touched. `(0,0)` to `(1,1)`. The GetTouchpadAxis method returns the coordinates of where the touchpad is being touched and can be used for directional input via the touchpad. The `x` value is the horizontal touch plane and the `y` value is the vertical touch plane. ### GetTouchpadAxisAngle/0 > `public float GetTouchpadAxisAngle()` * Parameters * _none_ * Returns * `float` - A float representing the angle of where the touchpad is being touched. `0f` to `360f`. The GetTouchpadAxisAngle method returns the angle of where the touchpad is currently being touched with the top of the touchpad being 0 degrees and the bottom of the touchpad being 180 degrees. ### GetTriggerAxis/0 > `public float GetTriggerAxis()` * Parameters * _none_ * Returns * `float` - A float representing the amount of squeeze that is being applied to the trigger. `0f` to `1f`. The GetTriggerAxis method returns a float that represents how much the trigger is being squeezed. This can be useful for using the trigger axis to perform high fidelity tasks or only activating the trigger press once it has exceeded a given press threshold. ### GetHairTriggerDelta/0 > `public float GetHairTriggerDelta()` * Parameters * _none_ * Returns * `float` - A float representing the difference in the trigger pressure from the hairline threshold start to current position. The GetHairTriggerDelta method returns a float representing the difference in how much the trigger is being pressed in relation to the hairline threshold start. ### AnyButtonPressed/0 > `public bool AnyButtonPressed()` * Parameters * _none_ * Returns * `bool` - Is true if any of the controller buttons are currently being pressed. The AnyButtonPressed method returns true if any of the controller buttons are being pressed and this can be useful to determine if an action can be taken whilst the user is using the controller. ## Example `SteamVR_Unity_Toolkit/Examples/002_Controller_Events` shows how the events are utilised and listened to. The accompanying example script can be viewed in `SteamVR_Unity_Toolkit/Examples/Resources/Scripts/VRTK_ControllerEvents_ListenerExample.cs`.