diff --git a/build.gradle b/build.gradle index 3d4f2c3..dfe0ab1 100644 --- a/build.gradle +++ b/build.gradle @@ -9,5 +9,6 @@ repositories { dependencies { compile fileTree(dir: 'lib', include: ['*.jar']) + compile 'com.1stleg:jnativehook:2.0.2' } diff --git a/lib/JNativeHook-1.3.jar b/lib/JNativeHook-1.3.jar deleted file mode 100644 index 388b533..0000000 Binary files a/lib/JNativeHook-1.3.jar and /dev/null differ diff --git a/src/main/java/org/fenix/llanfair/Llanfair.java b/src/main/java/org/fenix/llanfair/Llanfair.java index 8589443..fe77998 100644 --- a/src/main/java/org/fenix/llanfair/Llanfair.java +++ b/src/main/java/org/fenix/llanfair/Llanfair.java @@ -23,6 +23,8 @@ import java.io.FileWriter; import java.io.IOException; import java.io.InputStream; import java.util.Locale; +import java.util.logging.Level; +import java.util.logging.Logger; /** * Main frame executing Llanfair. @@ -93,6 +95,11 @@ public class Llanfair extends BorderlessFrame implements TableModelListener, * @param args array of command line parameters supplied at launch */ public static void main( String[] args ) { + // latest version of JNativeHook is a bit noisy logging-wise by default + Logger jnativehookLogger = Logger.getLogger(GlobalScreen.class.getPackage().getName()); + jnativehookLogger.setLevel(Level.WARNING); + jnativehookLogger.setUseParentHandlers(false); + if ( args.length > 0 ) { String locale = args[0]; LocaleDelegate.setDefault( new Locale( locale ) ); @@ -388,7 +395,11 @@ public class Llanfair extends BorderlessFrame implements TableModelListener, */ @Override public void windowClosed( WindowEvent event ) { Settings.save(); - GlobalScreen.unregisterNativeHook(); + try { + GlobalScreen.unregisterNativeHook(); + } catch (NativeHookException e) { + + } } @Override public void windowClosing(WindowEvent event) {} @@ -436,13 +447,17 @@ public class Llanfair extends BorderlessFrame implements TableModelListener, try { GlobalScreen.registerNativeHook(); } catch (NativeHookException e) { - throw new IllegalStateException("cannot register native hook"); + // NOTE: commenting this out as the latest version of JNativeHook has at least some ability to + // pop up an OS-specific dialog asking about accessibility permissions (at least on OS X) + // and afterwards the application recovered fine from the user's perspective. throwing an + // exception here causes Llanfair to just close immediately after the dialog has opened. + //throw new IllegalStateException("cannot register native hook"); } setAlwaysOnTop(Settings.GNR_ATOP.get()); addWindowListener(this); addMouseWheelListener(this); Settings.addPropertyChangeListener(this); - GlobalScreen.getInstance().addNativeKeyListener(this); + GlobalScreen.addNativeKeyListener(this); } /** diff --git a/src/main/java/org/fenix/llanfair/dialog/TabHotkeys.java b/src/main/java/org/fenix/llanfair/dialog/TabHotkeys.java index 04afff3..a3e7b4d 100644 --- a/src/main/java/org/fenix/llanfair/dialog/TabHotkeys.java +++ b/src/main/java/org/fenix/llanfair/dialog/TabHotkeys.java @@ -156,7 +156,7 @@ class TabHotkeys extends SettingsTab { public void mouseClicked(MouseEvent event) { if (!isEditing) { setBackground(Color.YELLOW); - GlobalScreen.getInstance().addNativeKeyListener(this); + GlobalScreen.addNativeKeyListener(this); isEditing = true; } } @@ -183,7 +183,7 @@ class TabHotkeys extends SettingsTab { int code = event.getKeyCode(); String text = null; - if (code == NativeKeyEvent.VK_ESCAPE) { + if (code == NativeKeyEvent.VC_ESCAPE) { code = -1; text = "" + Language.DISABLED; } else { @@ -193,7 +193,7 @@ class TabHotkeys extends SettingsTab { setting.set(code); setBackground(Color.GREEN); - GlobalScreen.getInstance().removeNativeKeyListener(this); + GlobalScreen.removeNativeKeyListener(this); isEditing = false; }