Added shutdown hook to ensure closure of global keyboard hook.

This commit is contained in:
neviyn 2016-03-15 03:56:12 +00:00
parent fab04af5a6
commit fb3c830b79

View File

@ -70,6 +70,8 @@ public class PlayerGUI implements PlayerCallbackInterface, LibraryCallbackInterf
try { try {
GlobalKeyboardHook keyboardHook = new GlobalKeyboardHook(); GlobalKeyboardHook keyboardHook = new GlobalKeyboardHook();
keyboardHook.addKeyListener(new GlobalKeyboardShortcuts()); keyboardHook.addKeyListener(new GlobalKeyboardShortcuts());
Thread hookShutdown = new Thread(keyboardHook::shutdownHook);
Runtime.getRuntime().addShutdownHook(hookShutdown);
} catch(RuntimeException | UnsatisfiedLinkError ex){ } catch(RuntimeException | UnsatisfiedLinkError ex){
System.out.println("Keyboard hook failed, global shortcuts will not work this session."); System.out.println("Keyboard hook failed, global shortcuts will not work this session.");
System.out.println(ex.getMessage()); System.out.println(ex.getMessage());