The 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();
}
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();
}
catch (NativeHookException ex) {
System.err.println("There was a problem registering the native hook.");
System.err.println(ex.getMessage());
ex.printStackTrace();
}
GlobalScreen.getInstance().addNativeKeyListener(new GlobalKeyListenerExample());
}
}
This is the same code as here in the 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 proprietary methods , and I also imported the GlobalScreen class.
And why am I getting a second error when I have already redefined it? But when I add the annotation @Overridebefore this method, the IDE gives an error saying that the method does not override or does not implement from the supertype.
source
share