kwhat/jnativehook

GlobalScreen class does not implement AutoCloseable, preventing usage in try-with-resources

Gauravkumar1502 opened this issue · 0 comments

Issue Description:

The GlobalScreen class from the JNativeHook library does not implement the AutoCloseable interface, making it inconvenient to use in try-with-resources statements.

Expected Behavior:

The GlobalScreen class should implement the AutoCloseable interface to allow for proper resource management using try-with-resources.

public class MyGlobalScreen implements AutoCloseable {
    // ... existing code ...

    /**
     * Close method to unregister the native hook.
     */
    @Override
    public void close() {
        try {
            GlobalScreen.unregisterNativeHook();
        } catch (NativeHookException e) {
            log.severe("Error unregistering native hook: " + e.getMessage());
        }
    }
}

Adding support for the AutoCloseable interface would enhance the usability of the library in applications that rely on try-with-resources statements for resource cleanup.