static L onGlobalKeyPress_listeners = synchroList(); // f: voidfunc(NativeKeyEvent) static AutoCloseable onGlobalKeyPress(fO f) { jnativehook_init(); final NativeKeyAdapter listener = new { public void nativeKeyPressed(NativeKeyEvent e) { pcallF(f, e); } }; GlobalScreen.addNativeKeyListener(addAndReturn(onGlobalKeyPress_listeners, listener)); ret autoCloseable { GlobalScreen.removeNativeKeyListener(listener); }; } static void cleanMeUp_onGlobalKeyPress() { for (NativeKeyAdapter a : getAndClearList(onGlobalKeyPress_listeners)) GlobalScreen.removeNativeKeyListener(a); }