Skip to content

Shutdown Hook problem when using JavaFX #475

@DavidTheExplorer

Description

@DavidTheExplorer

Hello, I'm trying to consume events within a JavaFX program.
It works well, but I discovered that closing the program doesn't run the shutdown hook.
Here is my code(called during startup by the UI thread):

private static void setupJNativeHook()
{
    try
    {
        GlobalScreen.setEventDispatcher(new VoidDispatchService());
        GlobalScreen.registerNativeHook();
    }
    catch(NativeHookException exception)
    {
        throw new IllegalStateException("Failed to enable JNativeHook", exception);
    }

    Runtime.getRuntime().addShutdownHook(new Thread(() ->
    {
        try
        {
            GlobalScreen.unregisterNativeHook();
        }
        catch(NativeHookException exception)
        {
            throw new IllegalStateException("Failed to unregister JNativeHook", exception);
        }
    }));
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions