Search Unity

  1. Get all the Unite Berlin 2018 news on the blog.
    Dismiss Notice
  2. Unity 2018.2 has arrived! Read about it here.
    Dismiss Notice
  3. Improve your Unity skills with a certified instructor in a private, interactive classroom. Learn more.
    Dismiss Notice
  4. ARCore is out of developer preview! Read about it here.
    Dismiss Notice
  5. Magic Leap’s Lumin SDK Technical Preview for Unity lets you get started creating content for Magic Leap One™. Find more information on our blog!
    Dismiss Notice
  6. 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:
    27
    when change to another app, then return to exe player, sometimes Input.GetKeyDown is not working,
     
  2. dujimache

    dujimache

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

    dujimache

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

    jeffreyschoch

    Joined:
    Jan 21, 2015
    Posts:
    2,241
    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:
    85
    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:
    27
    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:
    27
    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. }