-
Notifications
You must be signed in to change notification settings - Fork 351
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
SIGSEGV when registering hook in JavaFX application #442
Comments
do it like this public class Main extends Application {
@Override
public void start(Stage primaryStage) throws Exception{
// ...all your init stuff
new Thread(()->{
try {
Thread.sleep(1000);
} catch (InterruptedException e) {
e.printStackTrace();
}
registerHook();
}).start();
}
private void registerHook(){
try {
com.github.kwhat.jnativehook.GlobalScreen.registerNativeHook();
} catch (NativeHookException ex) {
System.err.println("There was a problem registering the native hook.");
System.err.println(ex.getMessage());
System.exit(1);
}
}
} Also the problem goes away in old versions: Also register your Listeners in the same way: @Inject
public GlobalHotKeyListener(EventBus eventBus) {
this.eventBus = eventBus;
// ugly workaround for bug in jnativehook - keep it like that
registerListener();
}
private void registerListener(){
new Thread(()->{
try {
Thread.sleep(1000);
} catch (InterruptedException e) {
e.printStackTrace();
}
GlobalScreen.addNativeKeyListener(this);
}).start();
} Had the same issue, this is my (very pretty) workaround. |
I ended up simplifying like this: public class Main extends Application{
@Override
public void start(Stage primaryStage) throws Exception {
// ...
// only for jnativehook 2.2.2:
// needs to be run on diff thread, otherwise segfault
Platform.runLater(this::registerHook);
}
private void registerHook() {
try {
GlobalScreen.registerNativeHook();
// must register here bc of thread issues and race conditions in jnativehook
GlobalScreen.addNativeMouseListener(myMouseListener);
GlobalScreen.addNativeKeyListener(myHotKeyListener);
} catch (NativeHookException e) {
log.error("Failed to register native hook", e);
System.exit(1);
}
}
} |
Title basically. I have a JavaFX application that throws SIGSEGV in line
GlobalScreen.registerNativeHook();
. When I remove that line, it doesn't exit but then the application doesn't work. I am running it with Java 17 on Ubuntu 20.04 64-bit. Also I'm using Maven to build it and JNativeHook 2.2.2. Here's the crash log if that helps: https://pastebin.com/hU6ahhaRThe text was updated successfully, but these errors were encountered: