⌨️
Thock
Get Thock
  • About
    • ⌨️Description
    • 🚀Quick Start
    • ™️Third-Party information
    • Sample Scenes
      • Example_ScreenTypewriter-and-Soundpacks
      • Example_Type
      • Example_StringEvents
  • Documentation
    • Thock
    • Convert JSON to Soundpack
      • ConvertJsonToSoundpack
    • Utilities
      • StringEventListener
        • StringEventListener Component Tutorial
      • KeyPressEventReceiver
      • KeyPressEventSender
    • Scriptable-Objects
      • SoundPackSO
      • IntToKeyCodeTable
      • StereoAudioMapping
      • StringToKeycodeTable
    • Types
      • SoundMap
Powered by GitBook
On this page
  1. Documentation
  2. Utilities

KeyPressEventSender

KeyPressEventSender.cs is a script that detects key press events and sends them to a specified receiver. It can send these events to a specific Thock instance or invoke a UnityEvent.

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.

PreviousKeyPressEventReceiverNextScriptable-Objects

Last updated 1 year ago