# GraffitiEventManager
Class Inherits GraffitiWebUIControl
## About
Take control of your Xojo Web applications' behavior by attaching to events not supported by the framework.
## Compatibility
### Framework API Version
| 1.0 | 2.0 |
| :---: | :---: |
| True | True |
### Web
| 32-Bit | 64-Bit |
| :---: | :---: |
| True | True |
## Enumerations
| Name | Value | Description |
| --- | :---: | --- |
| EventTypes | MouseDown <br> MouseUp <br> MouseMove <br> MouseEnter <br> MouseExit <br> KeyDown <br> KeyUp <br> KeyPress <br> TouchStart <br> TouchEnd <br> TouchMove <br> FocusIn <br> FocusOut <br> Copy <br> Paste <br> ContextMenu <br> DoubleClick <br> Scroll <br> ScrollEnd <br> Wheel | Supported event types. |
| MouseButtons | None <br> LeftButton <br> MiddleButton <br> RightButton | Supported mouse buttons. |
## Event Definitions
| Name | Parameters | Return Type | Description |
| --- | :---: | :---: | --- |
| CustomEvent | name as String <br> parameters as JSONItem | (None) | Raised when a custom JavaScript event has been received. |
| FocusEvent | name as String <br> type as GraffitiEventManager.EventTypes | (None) | Raised when a FocusIn or FocusOut event has been received. |
| KeyboardEvent | name as String <br> type as GraffitiEventManager.EventTypes <br> keyCode as Integer <br> metaKey as Boolean <br> shiftKey as Boolean <br> controlKey as Boolean <br> altKey as Boolean | (None) | Raised when a KeyDown, KeyUp, or KeyPress event has been received. |
| MouseButtonEvent | name as String <br> type as GraffitiEventManager.EventTypes <br> button as GraffitiEventManager.MouseButtons <br> relativePosition as Xojo.Point <br> metaKey as Boolean <br> shiftKey as Boolean <br> controlKey as Boolean <br> altKey as Boolean | (None) | Raised when a MouseDown or MouseUp event has been received. |
| MouseMoveEvent | name as String <br> type as GraffitiEventManager.EventTypes <br> relativePosition as Xojo.Point | (None) | Raised when the user has moved the mouse. relativePosition is relative to the (0,0) of the control. This event will only be raised when the mouse has been stationary for 500ms. |
| MousePresenceEvent | name as String <br> type as GraffitiEventManager.EventTypes | (None) | Raised when a MouseEnter or MouseExit event has been received. |
| Open | (None) | (None) | |
| Shown | (None) | (None) | |
## Methods
| Name | Parameters | Return Type | Description |
| --- | :---: | :---: | --- |
| Bind | name as String <br> element as Object <br> type as EventTypes | (None) | Binds the defined event to the provided element. |
| Bind | name as String <br> element as Object <br> type as EventTypes <br> customFunction as String | (None) | Binds the defined event to the provided element. |
| Bind | name as String <br> selector as String <br> type as EventTypes | (None) | Binds the defined event to the provided element. |
| Bind | name as String <br> selector as String <br> type as EventTypes <br> customFunction as String | (None) | Binds the defined event to the provided element. |
| BindWithFilter | name as String <br> element as Object <br> type as EventTypes <br> filterValues() as Integer | (None) | Used for filtering KeyCodes in the JavaScript responder for Keyboard events. |
| BindWithFilter | name as String <br> selector as String <br> type as EventTypes <br> filterValues() as Integer | (None) | Used for filtering KeyCodes in the JavaScript responder for Keyboard events. |
| Unbind | element as Object <br> type as EventTypes | (None) | Unbinds the defined event from the provided element. |
| Unbind | selector as String <br> type as EventTypes | (None) | Unbinds the defined event from the provided element. |
## Notes
### Binding Limitations
Each object and event type combination can only be bound once to help ensure that traffic is not overloaded with superfluous events. Developer should combine their event handlers as much as possible to reduce network traffic.
## Examples
### Bindings
```
'// Bind mouse presence events to WebButton
gemDemo.Bind( "button1_mousepresence", Button1, GraffitiEventManager.EventTypes.MouseEnter )
gemDemo.Bind( "button1_mousepresence", Button1, GraffitiEventManager.EventTypes.MouseExit )
'// Bind mouse interaction events to WebButton
gemDemo.Bind( "button_mouseevent", Button1, GraffitiEventManager.EventTypes.MouseDown )
gemDemo.Bind( "button_mouseevent", Button1, GraffitiEventManager.EventTypes.MouseUp )
gemDemo.Bind( "button_mouseevent", Button1, GraffitiEventManager.EventTypes.MouseMove )
'// Bind keyboard events to WebButton
gemDemo.Bind( "button1_keyboard", Button1, GraffitiEventManager.EventTypes.KeyDown )
gemDemo.Bind( "button1_keyboard", Button1, GraffitiEventManager.EventTypes.KeyUp )
'// Bind touch events to WebButton
gemDemo.Bind( "button1_touchevent", Button1, GraffitiEventManager.EventTypes.TouchStart )
gemDemo.Bind( "button1_touchevent", Button1, GraffitiEventManager.EventTypes.TouchEnd )
gemDemo.Bind( "button1_touchevent", Button1, GraffitiEventManager.EventTypes.TouchMove )
'// Bind custom JavaScript function to WebButton's MouseEnter event
gemDemo.Bind( "button1_customfunction", Button1, GraffitiEventManager.EventTypes.MouseEnter, jsCustomFunction )
'// Bind keyboard event to WebTextField
gemDemo.BindWithFilter( "textfield1_enterKey", TextField1, GraffitiEventManager.EventTypes.KeyDown, Array( 13 ) )
'// Bind focus events to WebTextField
gemDemo.Bind( "textfield1_focusIn", TextField1, GraffitiEventManager.EventTypes.FocusIn )
gemDemo.Bind( "textfield1_focusOut", TextField1, GraffitiEventManager.EventTypes.FocusOut )
```
### Sample Custom JavaScript Function
```
function (e) {
// sendToXojo function supports arrays or JavaScript objects.
$(e.target).html('Custom JS Event');
// sendToXojo([0, '1', false]); // Array
sendToXojo({'name' : 'value'}); // Object
}
```