Search Unity

Input.GetKeyDown is not working

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

  1. dujimache

    dujimache

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

    dujimache

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

    dujimache

    Joined:
    Dec 17, 2011
    Posts:
    89
    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:
    89
    anybody konw??
     
  5. LiterallyJeff

    LiterallyJeff

    Joined:
    Jan 21, 2015
    Posts:
    2,807
    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:
    338
    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:
    89
    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:
    89
    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. }