Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice
  3. Join us on November 16th, 2023, between 1 pm and 9 pm CET for Ask the Experts Online on Discord and on Unity Discussions.
    Dismiss Notice

New InputSystem and Event.current.keyCode

Discussion in 'Input System' started by immeasurability, Aug 7, 2021.

  1. immeasurability

    immeasurability

    Joined:
    Apr 22, 2014
    Posts:
    125
    Hi! i cant find way to get Key current pressed!
    I need get Key.{key} current pressed by keyboard as it was in old system Event.current.keyCode

    New InputSystem work by Key.{key} and old system (Event.current.keyCode) returns old format KeyCode.{key}

    What way to get info about what Key.{key} was pressed?

    Key.{key} != KeyCode.{key}

    i need analog of Event.current.keyCode and result of return i need Key! NOT KeyCode!
     
  2. immeasurability

    immeasurability

    Joined:
    Apr 22, 2014
    Posts:
    125
    What way to get info about what Key.{key} was pressed?
     
  3. immeasurability

    immeasurability

    Joined:
    Apr 22, 2014
    Posts:
    125
    Best support! thx!
     
  4. nikescar

    nikescar

    Joined:
    Nov 16, 2011
    Posts:
    163
    https://docs.unity3d.com/Packages/com.unity.inputsystem@0.9/manual/Migration.html

    Code (CSharp):
    1. // Using KeyControl property directly.
    2. Keyboard.current.spaceKey.wasPressedThisFrame
    3. Keyboard.current.aKey.wasPressedThisFrame // etc.
    4.  
    5. // Using Key enum.
    6. Keyboard.current[Key.Space].wasPressedThisFrame
    7.  
    8. // Using key name.
    9. ((KeyControl)Keyboard.current["space"]).wasPressedThisFrame
     
    sajkowart likes this.
  5. immeasurability

    immeasurability

    Joined:
    Apr 22, 2014
    Posts:
    125
    I need NOT check special KEY! in u code only this return fact of key Keyboard.current.aKey.wasPressedThisFrame BUT this return only BOOL not the key!

    U see this > (Event.current.keyCode) what this code return? bool or key?
    Check this pls first > https://docs.unity3d.com/ScriptReference/Event-keyCode.html
     
  6. nikescar

    nikescar

    Joined:
    Nov 16, 2011
    Posts:
    163
    Oh! Sorry about not reading more carefully.

    Yeah, the only way that spring to mind to do that with the keyboard is to use Keyboard.current.onTextInput but that's only useful if you are trying to detect a keypress that is a character.

    Otherwise less optimal solutions like THIS are needed:

     
    esco1979 likes this.
  7. immeasurability

    immeasurability

    Joined:
    Apr 22, 2014
    Posts:
    125
    Unity disappointing. Too much bugs and problems.
     
  8. Ryiah

    Ryiah

    Joined:
    Oct 11, 2012
    Posts:
    20,150
    Why?
     
  9. immeasurability

    immeasurability

    Joined:
    Apr 22, 2014
    Posts:
    125
    Who?
     
  10. OUTTAHERE

    OUTTAHERE

    Joined:
    Sep 23, 2013
    Posts:
    656
    e.g. if you want to write a filter control, that is invisible until any alphanumeric key is pressed; and then not swallow the first keypress, but be a good application and pass that key press on to the control?