Search Unity

Receive key down for evey key pressed anywhere inside the editor

Discussion in 'Immediate Mode GUI (IMGUI)' started by lucasmontec, Nov 29, 2017.

  1. lucasmontec

    lucasmontec

    Joined:
    Apr 7, 2015
    Posts:
    97
    Hey guys, whats up?
    I'm trying to receive a key down (or key used) event, and its key up later, in an editor window. The only problem is that the window only receives this event when its focused.

    I use this key state to enable/disable a specific behaviour of my buttons, so when the user holds the key, the buttons must change color, to indicate that they will behave differently.

    My script is an EditorWindow extension. I'm using key events read from Event.current, and reading them inside OnGUI. I improved my results by making the window listen to mouse enter/leave and mouse move. Still, if the user presses the key on top of the window (unfocused), and doesn't move the mouse, no events fire and the window stays the same. Also if the user presses the key outside of the window, no events fire either.

    Is there a way of getting those events correctly? I'll need to hook into win32 api to read them? If so, I'll probably need to do the same for linux and mac...
     
  2. lucasmontec

    lucasmontec

    Joined:
    Apr 7, 2015
    Posts:
    97