# KeyPressEventSender

**Key Selection**

* `Key` (KeyCode): The key that this script is listening for.

**Settings**

* `ListenInUpdate` (bool): If true, the script will check for key presses in the Update method.
* `isSenderThockGameObject` (bool): If true, the script will send key press events to a specific Thock instance.
* `sender` (SenderType): Determines where this script should send key press events. Can be either `SendToThockGameObject` or `SendToThockInstance`.

**Thock Reference**

* `Reference` (Thock): The Thock instance that this script will send key press events to. This is only used if `sender` is set to `SendToThockGameObject`.

**Events**

* `OnKeyPress` (UnityEvent): Event that is invoked when the specified key is pressed.
* `OnKeyPressAction` (Action): Static event that is invoked when the specified key is pressed.

#### Public Methods

* `PressKey()` (void): Invokes the `OnKeyPress` event and sends a key press event to the specified Thock instance.
* `SetKey(string str)` (void): Sets the key that this script is listening for. The key is passed as a string and converted to a KeyCode.

#### Private Methods

* `CheckKey()` (void): Checks if the specified key is pressed. If it is, the `PressKey` method is called.
* `SendKeyPressToThock(KeyCode key)` (void): Sends a key press event to the specified Thock instance.

#### Unity Methods

* `Update()` (void): If `ListenInUpdate` is true, the `CheckKey` method is called in this method.
* `OnValidate()` (void): Sets `isSenderThockGameObject` based on the `sender` setting.

This script should be attached to a GameObject in your scene. You can specify the key to listen for and the sender type in the Inspector. When the specified key is pressed, the `OnKeyPress` event will be invoked and a key press event will be sent to the specified Thock instance.


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://tobar-io.gitbook.io/thock/documentation/utilities/keypresseventsender.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
