This repository was archived by the owner on Feb 28, 2026. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathHotKey.cs
More file actions
83 lines (71 loc) · 2.21 KB
/
Copy pathHotKey.cs
File metadata and controls
83 lines (71 loc) · 2.21 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
72
73
74
75
76
77
78
79
80
81
82
83
using System;
using System.Collections.Generic;
using System.Windows.Forms;
namespace PowerCacheOffice
{
internal partial class HotKey : Form
{
public static readonly int MOD_KEY_NONE = 0;
public static readonly int MOD_KEY_ALT = 1;
public static readonly int MOD_KEY_CONTROL = 2;
public static readonly int MOD_KEY_SHIFT = 4;
public event EventHandler OnHotKey = delegate { };
private readonly int WM_HOTKEY = 0x0312;
private List<int> ids = new List<int>();
protected override void WndProc(ref Message m)
{
base.WndProc(ref m);
if (m.Msg == WM_HOTKEY) OnHotKey(this, new HotKeyEventArgs((int)m.WParam));
}
public bool Add(int modKey, Keys key, int id)
{
if (NativeMethods.RegisterHotKey(this.Handle, id, modKey, key) != 0)
{
if (!ids.Contains(id)) ids.Add(id);
return true;
}
return false;
}
public bool Remove(int id)
{
if (NativeMethods.UnregisterHotKey(this.Handle, id) != 0)
{
if (ids.Contains(id)) ids.Remove(id);
return true;
}
return false;
}
public void RemoveAll()
{
ids.ForEach(x => NativeMethods.UnregisterHotKey(this.Handle, x));
ids = new List<int>();
}
protected override void Dispose(bool disposing)
{
ids.ForEach(x => NativeMethods.UnregisterHotKey(this.Handle, x));
if (disposing && (components != null)) components.Dispose();
base.Dispose(disposing);
}
public class HotKeyEventArgs : EventArgs
{
public int Id;
public HotKeyEventArgs(int id)
{
Id = id;
}
}
public HotKey()
{
InitializeComponent();
}
private void HotKey_Load(object sender, EventArgs e)
{
this.Visible = false;
this.FormClosing += (s, eventArgs) =>
{
this.Visible = false;
eventArgs.Cancel = true;
};
}
}
}