-
Notifications
You must be signed in to change notification settings - Fork 0
/
GlobalMouseKeyboard.cs
55 lines (46 loc) · 1.73 KB
/
GlobalMouseKeyboard.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
46
47
48
49
50
51
52
53
54
55
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using MouseKeyboardActivityMonitor; //http://globalmousekeyhook.codeplex.com/
using MouseKeyboardActivityMonitor.WinApi;
using System.Windows.Forms;
namespace Trollkit {
class GlobalMouseKeyboard //TODO: should probably make this static instead...
{
private readonly KeyboardHookListener keyboardHookManager;
public Boolean F2IsPressed { get; set; }
public Boolean F4IsPressed { get; set; }
public GlobalMouseKeyboard() {
keyboardHookManager = new KeyboardHookListener(new GlobalHooker());
keyboardHookManager.Enabled = true;
hookInputs();
}
private void hookInputs() {
//keyboardHookManager.KeyPress += hookManager_KeyPress; //non-character keys are not captured by KeyPress
keyboardHookManager.KeyUp += hookManager_KeyUp;
}
private void unhookInputs() {
//keyboardHookManager.KeyPress -= hookManager_KeyPress;
keyboardHookManager.KeyUp -= hookManager_KeyUp;
}
private void hookManager_KeyUp(object sender, KeyEventArgs e) {
//F2IsPressed = false; //this worked for KeyPress somehow
//F4IsPressed = false;
if (e.KeyCode == Keys.F2) //TODO: control + R, control + S or E
{
F2IsPressed = true;
e.Handled = true;
}
if (e.KeyCode == Keys.F4) {
F4IsPressed = true;
e.Handled = true;
}
}
public void Dispose() //TODO: need to learn .NET disposal
{
unhookInputs();
keyboardHookManager.Dispose();
}
}
}