Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

why do i get these errors?

Tags:

java

Code :

package keylogger;

import org.jnativehook.GlobalScreen;
import org.jnativehook.NativeHookException;
import org.jnativehook.keyboard.NativeKeyEvent;
import org.jnativehook.keyboard.NativeKeyListener;

public class GlobalKeyListenerExample implements NativeKeyListener {
    public void nativeKeyPressed(NativeKeyEvent e) {
            System.out.println("Key Pressed: " + NativeKeyEvent.getKeyText(e.getKeyCode()));

            if (e.getKeyCode() == NativeKeyEvent.VK_ESCAPE) {
                    try {
                            GlobalScreen.unregisterNativeHook(); // LINE 18
                    }
                    catch (NativeHookException ex) {
                            System.err.println("You cannot call unregisterNativeHook() from the native dispatch thread.");
                    }
            }
    }


    public void nativeKeyReleased(NativeKeyEvent e) {
            System.out.println("Key Released: " + NativeKeyEvent.getKeyText(e.getKeyCode()));
    }

    public void nativeKeyTyped(NativeKeyEvent e) {
            System.out.println("Key Typed: " + NativeKeyEvent.getKeyText(e.getKeyCode()));
    }


    public static void main(String[] args) {
            try {
                    GlobalScreen.registerNativeHook(); // LINE 38
            }
            catch (NativeHookException ex) {
                    System.err.println("There was a problem registering the native hook.");
                    System.err.println(ex.getMessage());
                    ex.printStackTrace();
            }

            //Construct the example object and initialze native hook.
            GlobalScreen.getInstance().addNativeKeyListener(new GlobalKeyListenerExample());
    }
}

This is same code as given here on google code. I downloaded and then used the JNativeHost library in my project. But i get the following errors :

Cannot find unregisterNativeHook,registerNativeHook. //(line 18,38)
The IDE also says GlobalKeyListenerExample is not abstract and doesn't override abstract method keyReleased. 

To the first error the methods are defined here and they are native methods and i also have imported the GlobalScreen class.

And why do i get the second error when i have already overrided that ? But when i add a @Override annotation before that method IDE gives an error saying the method doesn't override or implement from a supertype.

like image 450
program-o-steve Avatar asked Mar 04 '26 15:03

program-o-steve


1 Answers

Everything is fine ! One thing that i think could be wrong is the version of the library you might be using against the code you have copied and pasted ! Use the marked library below. You can download it from here

enter image description here

From the comments i guess you are using netbeans. Add this jar file to your library.

like image 193
Suhail Gupta Avatar answered Mar 07 '26 06:03

Suhail Gupta



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!