-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathKeyHandler.cs
More file actions
33 lines (26 loc) · 798 Bytes
/
KeyHandler.cs
File metadata and controls
33 lines (26 loc) · 798 Bytes
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
using System.Windows.Forms;
using System;
using System.Runtime.InteropServices;
public class KeyHandler {
[DllImport("user32.dll")]
private static extern bool RegisterHotKey(IntPtr hWnd, int id, int fsModifiers, int vk);
[DllImport("user32.dll")]
private static extern bool UnregisterHotKey(IntPtr hWnd, int id);
private int key;
private IntPtr hWnd;
private int id;
public KeyHandler(Keys key, Form form) {
this.key = (int)key;
this.hWnd = form.Handle;
id = this.GetHashCode();
}
public override int GetHashCode() {
return key ^ hWnd.ToInt32();
}
public bool Register() {
return RegisterHotKey(hWnd, id, 0, key);
}
public bool Unregiser() {
return UnregisterHotKey(hWnd, id);
}
}