-
Notifications
You must be signed in to change notification settings - Fork 15
Expand file tree
/
Copy pathHotKeyManager.cs
More file actions
30 lines (27 loc) · 917 Bytes
/
Copy pathHotKeyManager.cs
File metadata and controls
30 lines (27 loc) · 917 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
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace CommonLibrary.CodeSystem
{
internal class HotKeyManager
{
public static void AddHotKey(Form form, Action function, Keys key, bool ctrl = false, bool shift = false, bool alt = false)
{
form.KeyPreview = true;
form.KeyDown += delegate (object sender, KeyEventArgs e)
{
if (IsHotkey(e, key, ctrl, shift, alt))
{
function();
}
};
}
public static bool IsHotkey(KeyEventArgs eventData, Keys key, bool ctrl = false, bool shift = false, bool alt = false)
{
return eventData.KeyCode == key && eventData.Control == ctrl && eventData.Shift == shift && eventData.Alt == alt;
}
}
}