Search Unity

  1. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

What is the correct way to check if an InputAction callback is issued from a keyboard binding?

Discussion in 'Input System' started by dlorre, Aug 20, 2021.

  1. dlorre

    dlorre

    Joined:
    Apr 12, 2020
    Posts:
    700
    Actually I am looking if.context.control.device.name contains "keyboard", is it safe to do like this?
     
  2. Rene-Damm

    Rene-Damm

    Joined:
    Sep 15, 2012
    Posts:
    1,779
    Bit more robust.

    Code (CSharp):
    1. if (context.control.device is Keyboard)
    2.    Debug.Log("Keyboard");
    There's also OnControlsChanged which can be used to determine what kind of control setup is being used ATM.
     
    dlorre likes this.