-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathKeyLogger.java
40 lines (34 loc) · 1.15 KB
/
KeyLogger.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
import java.io.FileWriter;
import java.io.PrintWriter;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Scanner;
public class KeyLogger {
private static final String fName = "keyStrokes.txt";
public static void main(String[] args) {
startKeyLogging();
}
private static void startKeyLogging() {
try {
PrintWriter pw = new PrintWriter(new FileWriter(fName, true));
Scanner sc = new Scanner(System.in);
while (true) {
String input = sc.nextLine();
if (input.equalsIgnoreCase("exit")) {
break;
}
String timeStamp = getCurrentTimeStamp();
pw.println(timeStamp+ ": "+ input);
pw.flush();
}
pw.close();
sc.close();
} catch (Exception e) {
e.printStackTrace();
}
}
private static String getCurrentTimeStamp() {
SimpleDateFormat sDateFormat = new SimpleDateFormat("dd-MM-yyyy HH:mm:ss");
return sDateFormat.format(new Date());
}
}