⌨️
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

KeyPressEventReceiver

PreviousStringEventListener Component TutorialNextKeyPressEventSender

Last updated 1 year ago

Key Selection

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

Settings

  • Listener (ListenerType): Determines where this script should listen for key press events. Can be either Class or Class via Singleton Instance.

Events

  • OnKeyPressReceived (UnityEvent): Event that is invoked when the specified key is pressed. The key is passed as a string.

Public Methods

  • OnKeyPress(KeyCode obj) (void): Method that is called when a key is pressed. If the pressed key matches the specified key, OnKeyPressReceived is invoked.

  • StopListening() (void): Unsubscribes this script from key press events.

  • 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

  • UnsubscribeFromKeyPressEvents() (void): Unsubscribes this script from key press events. This is called when the script is disabled or destroyed.

Unity Methods

  • Start() (void): Subscribes this script to key press events based on the Listener setting.

  • OnDestroy() (void): Unsubscribes this script from key press events when the script is destroyed.

  • OnDisable() (void): Unsubscribes this script from key press events when the script is disabled.

This script should be attached to a GameObject in your scene. You can specify the key to listen for and the listener type in the Inspector. When the specified key is pressed, the OnKeyPressReceived event will be invoked.

KeyPressEventSender
Thock