-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathProgram.cs
45 lines (36 loc) · 1.45 KB
/
Program.cs
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
using System;
using System.Diagnostics;
using System.Runtime.InteropServices;
using System.Windows.Input;
namespace KeyboardHookLite;
internal class Program
{
// Here is a demo of the library in action
static void Main(string[] args)
{
KeyboardHook kb = new KeyboardHook();
kb.KeyboardPressed += Kb_KeyboardPressed;
System.Windows.Threading.Dispatcher.Run();
kb.Dispose();
}
private static void Kb_KeyboardPressed(object? sender, KeyboardHookEventArgs e)
{
// Outputs the pressed type of key press.
// WM_KEYDOWN, WM_SYSKEYDOWN, WM_KEYUP, WM_SYSKEYUP
Console.WriteLine(e.KeyPressType);
// Outputs the pressed Key (of type System.Windows.Input).
Console.WriteLine(e.InputEvent.Key);
// Outputs the virtual key code.
Console.WriteLine(e.InputEvent.VirtualCode);
// Outputs a hardware scan code for the key.
Console.WriteLine(e.InputEvent.HardwareScanCode);
// Outputs the extended-key flag, event-injected Flags,
// context code, and transition-state flag.
Console.WriteLine(e.InputEvent.Flags);
// Outputs the time stamp stamp for this message, equivalent
// to what GetMessageTime would return for this message.
Console.WriteLine(e.InputEvent.TimeStamp);
// Outputs additional information associated with the message.
Console.WriteLine(e.InputEvent.AdditionalInformation);
}
}