// This works when the ctrl key is pressed/released when a Swing window // is in focus or the mouse is inside a Swing window. // If you press ctrl before the program starts and the mouse is never // inside any of the windows, the key press will not be registered. static AutoCloseable tempAddGlobalCtrlKeyListener(IVF1 onStatusChanged) { AWTEventListener l = new AWTEventListener { Bool status; public void eventDispatched(AWTEvent evt) { if (evt cast InputEvent) { Bool b = evt.isControlDown(); if (!eq(b, status)) pcallF_typed(onStatusChanged, status = b); } } }; Toolkit.getDefaultToolkit().addAWTEventListener(l, AWTEvent.KEY_EVENT_MASK | AWTEvent.MOUSE_EVENT_MASK | AWTEvent.MOUSE_MOTION_EVENT_MASK); ret -> Toolkit.getDefaultToolkit().removeAWTEventListener(l); }