// OnGUI is called for rendering and handling GUI events public void OnGUI() { if (GameSettings.Instance.game.showDFScreen) { Event e = Event.current; if (e.isKey) { RemoteFortressReader.KeyboardEvent dfEvent = new RemoteFortressReader.KeyboardEvent(); switch (e.type) { case EventType.KeyDown: dfEvent.type = 2; dfEvent.state = 0; break; case EventType.KeyUp: dfEvent.type = 3; dfEvent.state = 0; break; } SDL.Mod mod = SDL.Mod.KMOD_NONE; if (e.shift) { mod |= SDL.Mod.KMOD_SHIFT; } if (e.control) { mod |= SDL.Mod.KMOD_CTRL; } if (e.alt) { mod |= SDL.Mod.KMOD_ALT; } if (e.command) { mod |= SDL.Mod.KMOD_META; } if (e.capsLock) { mod |= SDL.Mod.KMOD_CAPS; } dfEvent.mod = (uint)mod; dfEvent.scancode = (uint)e.keyCode; dfEvent.sym = (uint)e.keyCode; dfEvent.unicode = e.character; if (e.keyCode == KeyCode.None && e.character != '\0') { StartCoroutine(delayedKeyboardEvent(dfEvent)); // Unity doesn't give any keyboard events for character up, but DF expect it. } else { keyPresses.Enqueue(dfEvent); } } } }
public IEnumerator delayedKeyboardEvent(RemoteFortressReader.KeyboardEvent dfEvent) { keyPresses.Enqueue(dfEvent); yield return(new WaitForSeconds(0.1f)); dfEvent.type = 3; dfEvent.state = 0; keyPresses.Enqueue(dfEvent); }