Search Unity

  1. Check out the Unite LA keynote for updates on the Visual Effect Editor, the FPS Sample, ECS, Unity for Film and more! Watch it now!
    Dismiss Notice
  2. The Unity Pro & Visual Studio Professional Bundle gives you the tools you need to develop faster & collaborate more efficiently. Learn more.
    Dismiss Notice
  3. Improved Prefab workflow (includes Nested Prefabs!), 2D isometric Tilemap and more! Get the 2018.3 Beta now.
    Dismiss Notice
  4. Improve your Unity skills with a certified instructor in a private, interactive classroom. Watch the overview now.
    Dismiss Notice
  5. Want to see the most recent patch releases? Take a peek at the patch release page.
    Dismiss Notice

Input.GetKeyDown is not working

Discussion in 'Scripting' started by dujimache, Jul 14, 2018.

  1. dujimache

    dujimache

    Joined:
    Dec 17, 2011
    Posts:
    29
    when change to another app, then return to exe player, sometimes Input.GetKeyDown is not working,
     
  2. dujimache

    dujimache

    Joined:
    Dec 17, 2011
    Posts:
    29
    unity version is 5.6.5f1 32bit
     
  3. dujimache

    dujimache

    Joined:
    Dec 17, 2011
    Posts:
    29
    I used Input.GetKeyDown in Update function.when Input.GetKeyDown is not working, the Input.inputString has right value.And no matter any key you click, the Input.anykeydown is always false.But when you press mouse, the Input.anykeydow has right value. Windows 7. Unity 5.6.5 f1
     
  4. dujimache

    dujimache

    Joined:
    Dec 17, 2011
    Posts:
    29
    anybody konw??
     
  5. jeffreyschoch

    jeffreyschoch

    Joined:
    Jan 21, 2015
    Posts:
    2,305
    Could you share the code that's not working correctly? Hard to say what your problem is without seeing the code.

    Please use the code button or code tags when pasting it please.
     
    Kiwasi likes this.
  6. FernandoHC

    FernandoHC

    Joined:
    Feb 6, 2018
    Posts:
    254
    Since you mentioned about the mouse click, this sound like it could be an app focus/Select issue.
    I would have a look at:
    MonoBehaviour.OnApplicationFocus(bool), make some testings, maybe force select or focus some object inside unity so that it starts working again properly.
    Something you could do is also enable unity to run on background.
     
  7. dujimache

    dujimache

    Joined:
    Dec 17, 2011
    Posts:
    29
    run on background is also selected.When press mouse, the input.anykeydow is detected,but just cann't detect keyboard.
     
  8. dujimache

    dujimache

    Joined:
    Dec 17, 2011
    Posts:
    29
    Code (CSharp):
    1. void Update () {
    2.  
    3.         if (Input.GetKeyDown(KeyCode.Q))
    4.         {
    5.             var panel = transform.parent.GetComponent<PanelMain>();
    6.             panel.PressGemSkillBtn(GEM_PROP_TYPE.GEM_LOCK);
    7.         }
    8. }