Search Unity

Keyboard making "Invalid sound" in custom editor windows?

Discussion in 'Immediate Mode GUI (IMGUI)' started by Futurerobot, Nov 21, 2012.

  1. Futurerobot

    Futurerobot

    Joined:
    Jul 13, 2011
    Posts:
    179
    I'm having a problem with a custom editor window we created for our game, hope this is the right forum for it.

    I was using an Event in OnGui() in order to accept a keyboard input for it, which works fine, but whenever the window is selected it seems like any keyboard input is considered invalid. Pressing a key makes the standard "please don´t do that..." sound a mac makes ("DUN!")

    The input is still registered though, so that part works. Just need to get rid of the annoying sound (without muting the mac).
     
  2. Catsoft-Studios

    Catsoft-Studios

    Joined:
    Jan 15, 2011
    Posts:
    703
    I know I'm 5 years late, but since this post is the first I stumbled when looking for this particular issue, here's the solution.

    When the EditorWindows doesn't have an active control listening for keyboard inputs it makes this "invalid sound". This is normal. What happens when you capture these events through code? It still makes the sound because even though you are capturing the key pressed (through Event.current.type and Event.current.keyCode) you are not telling Unity "hey! I'm using this key!"

    TL;DR solution

    To solve this issue, simply call Event.current.Use() to tell Unity you are using that key stroke for something.
    Cheers!
     
  3. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,401
    Whoa, that works! And here I've been hitting the mute button all this time.

    --Eric
     
  4. Catsoft-Studios

    Catsoft-Studios

    Joined:
    Jan 15, 2011
    Posts:
    703
    Glad I helped ;-)