-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathProgram.cs
More file actions
71 lines (67 loc) · 2.62 KB
/
Program.cs
File metadata and controls
71 lines (67 loc) · 2.62 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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
using System;
using System.Threading;
using System.Windows.Forms;
namespace LowLevelControls.Sample2
{
static class Program
{
static KeyboardHook kbdHook = new KeyboardHook();
static MouseHook msHook = new MouseHook();
static void Main(string[] args)
{
kbdHook.KeyDownEvent += (sender, vkCode, injected) =>
{
Console.WriteLine((Keys)vkCode + " Down" + (injected ? " (Injected)" : ""));
return false;
};
kbdHook.KeyPressEvent += (sender, vkCode, injected) =>
{
Console.WriteLine((Keys)vkCode + " Press" + (injected ? " (Injected)" : ""));
return false;
};
kbdHook.KeyUpEvent += (sender, vkCode, injected) =>
{
Console.WriteLine((Keys)vkCode + " Up" + (injected ? " (Injected)" : ""));
return false;
};
msHook.MouseDownEvent += (sender, vkCode, x, y, delta, injected) =>
{
Console.WriteLine((Keys)vkCode + $" Down on ({x}, {y})" + (injected ? " (Injected)" : ""));
return false;
};
msHook.MouseUpEvent += (sender, vkCode, x, y, delta, injected) =>
{
Console.WriteLine((Keys)vkCode + $" Up on ({x}, {y})" + (injected ? " (Injected)" : ""));
return false;
};
msHook.MouseMoveEvent += (sender, vkCode, x, y, delta, injected) =>
{
Console.WriteLine($"Mouse Move to ({x}, {y})" + (injected ? " (Injected)" : ""));
return false;
};
msHook.MouseWheelEvent += (sender, vkCode, x, y, delta, injected) =>
{
Console.WriteLine($"Mouse Wheel with data {delta} on ({x}, {y})" + (injected ? " (Injected)" : ""));
return false;
};
msHook.MouseHWheelEvent += (sender, vkCode, x, y, delta, injected) =>
{
Console.WriteLine($"Mouse HWheel with data {delta} on ({x}, {y})" + (injected ? " (Injected)" : ""));
return false;
};
AppDomain.CurrentDomain.ProcessExit += CurrentDomain_ProcessExit;
kbdHook.InstallGlobalHook();
msHook.InstallGlobalHook();
for (;;)
{
Thread.Sleep(1);
Application.DoEvents();
}
}
private static void CurrentDomain_ProcessExit(object sender, EventArgs e)
{
kbdHook.UninstallGlobalHook();
msHook.UninstallGlobalHook();
}
}
}