public IEnumerator CloseWithKeyboard() { var dialog = OpenDialog(); yield return(null); var rootElement = dialog.rootVisualElement; rootElement.Focus(); var escapeKeyEvent = new Event { type = EventType.KeyUp, keyCode = KeyCode.Escape }; using (var keyUpEvent = KeyUpEvent.GetPooled(escapeKeyEvent)) { rootElement.SendEvent(keyUpEvent); } yield return(null); // The window should have been closed and destroy by then. Assert.IsTrue(!dialog); }
internal static EventBase CreateEvent(Event systemEvent) { switch (systemEvent.type) { case EventType.MouseMove: return(MouseMoveEvent.GetPooled(systemEvent)); case EventType.MouseDrag: return(MouseMoveEvent.GetPooled(systemEvent)); case EventType.MouseDown: return(MouseDownEvent.GetPooled(systemEvent)); case EventType.MouseUp: return(MouseUpEvent.GetPooled(systemEvent)); case EventType.ScrollWheel: return(WheelEvent.GetPooled(systemEvent)); case EventType.KeyDown: return(KeyDownEvent.GetPooled(systemEvent)); case EventType.KeyUp: return(KeyUpEvent.GetPooled(systemEvent)); case EventType.MouseEnterWindow: return(MouseEnterWindowEvent.GetPooled(systemEvent)); case EventType.MouseLeaveWindow: return(MouseLeaveWindowEvent.GetPooled(systemEvent)); default: return(IMGUIEvent.GetPooled(systemEvent)); } }
// In order for tests to run without an EditorWindow but still be able to send // events, we sometimes need to force the event type. IMGUI::GetEventType() (native) will // return the event type as Ignore if the proper views haven't yet been // initialized. This (falsely) breaks tests that rely on the event type. So for tests, we // just ensure the event type is what we originally set it to when we sent it. internal static EventBase CreateEvent(Event systemEvent, EventType eventType) { switch (eventType) { case EventType.MouseMove: return(MouseMoveEvent.GetPooled(systemEvent)); case EventType.MouseDrag: return(MouseMoveEvent.GetPooled(systemEvent)); case EventType.MouseDown: return(MouseDownEvent.GetPooled(systemEvent)); case EventType.MouseUp: return(MouseUpEvent.GetPooled(systemEvent)); case EventType.ContextClick: return(ContextClickEvent.GetPooled(systemEvent)); case EventType.MouseEnterWindow: return(MouseEnterWindowEvent.GetPooled(systemEvent)); case EventType.MouseLeaveWindow: return(MouseLeaveWindowEvent.GetPooled(systemEvent)); case EventType.ScrollWheel: return(WheelEvent.GetPooled(systemEvent)); case EventType.KeyDown: return(KeyDownEvent.GetPooled(systemEvent)); case EventType.KeyUp: return(KeyUpEvent.GetPooled(systemEvent)); case EventType.DragUpdated: return(DragUpdatedEvent.GetPooled(systemEvent)); case EventType.DragPerform: return(DragPerformEvent.GetPooled(systemEvent)); case EventType.DragExited: return(DragExitedEvent.GetPooled(systemEvent)); case EventType.ValidateCommand: return(ValidateCommandEvent.GetPooled(systemEvent)); case EventType.ExecuteCommand: return(ExecuteCommandEvent.GetPooled(systemEvent)); default: // Layout, Ignore, Used return(IMGUIEvent.GetPooled(systemEvent)); } }