Using the Simple Input Listener

If you want to be able to assign an event to fire off when the player presses a button, then the **Simple Input Listener** script is what you are looking for. To get started using it, just type the word "**Input**" into the Editor Search Bar. You'll find "**SimpleInputListener**" as one of the results.

You'll then want to drag that script onto an Empty Object that you have created. Once you have, you will be presented with these options:

* **Input Type**: You can choose whether it's a keyboard button or a mouse button you want to map an event to.
* **Keyboard / Mouse Button**: Choose which button will fire off the event.
* **On Button Down**: Any event placed here will execute when the button is pressed down.
* **On Button Up**: Any event placed here will execute when the button is released.

The Button drop down field is context sensitive based off what choice you made in the Input type field.

Mouse key options are just the standard Left Mouse Button, Right Mouse Button, and Middle Mouse Button.

The keyboard options include pretty much all keys on the keyboard even the Function Keys.

### How to Make it Work

Once you have chosen Mouse or Keyboard and picked your button of choice, you now need to hook up what you want it to do. As mentioned above, you'll want to create an event in either the "**On Button Down**" or "**On Button Up**" event fields.

Click the "**+**" button under the field to create an event, and then drag the object you want to affect into the slot. The pull down menu will then give you options of what can be done to that object (at a most basic level every object can be activated/deactivated).

### Using it with Trigger Volumes

By default, anything placed into the Simple Input Listener event field would be fired off every time you press the button. This is great if you are swinging a sword or firing a gun. But if you want to do something like having to press a button to interact with an object or an NPC, and you only want that to happen when you are standing near the object, then you will most likely want to hook up your Simple Input Listener object into a trigger volume to help control when the button can actually be used. Set up to do this is fairly simple.

First you'll want to deactivate the Simple Input Listener script. Simply click the box that is next to the paper looking icon found on the upper left corner of the script

Then you'll want to create a trigger volume around the object you'll want your player to interact with.

Drag your Simple Input Listener object into the "**On Trigger Entered**" field and in the pull down menu choose the "**SimpleInputListener/bool Enabled**" option and check the box under that. This will turn on the Input Listener Script when you enter the trigger and allow the button to do whatever is assigned to it

You'll also want to set up the reverse on the "**On Trigger Exited**" field by dropping the same object in there and choosing the same option, but this time making sure the check box is unchecked.

### Using it with the Switch Gate Script

What if you wanted to do something like being able to turn a light on and then off with a button press? You can't do that with just the Simple Input Script alone because the button event would either turn the light on or off. This is where the **Switch Gate** script comes in handy. This script allows you to set up two different event groups to fire off; one firing off when you press the button the first time, and then another firing off when you press it again. To start using it just type in the word "**Switch**" in the Editor Search Bar

You'll then want to drag the script onto an Empty Object. Once you do you will see these two fields:

* **On State Active Entered**: anything placed in these event fields will be fired off the first time you press the button.
* **On State Deactive Entered**: anything placed here will be fired off the second time you press the button.

The event will then cycle back and forth each time you press the button going from the Active field to the Deactive field, back to the active field, etc. Just like flipping a light switch. In the example below you can see that the Switcher has been set up to turn on and off a pair of objects when the button is pressed..