forked from BornToBeRoot/NETworkManager
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathHotKeys.cs
More file actions
98 lines (82 loc) · 2.96 KB
/
HotKeys.cs
File metadata and controls
98 lines (82 loc) · 2.96 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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
using System.Windows.Input;
namespace NETworkManager.Utilities
{
/// <summary>
/// Class provides static methods for hotkeys.
/// </summary>
public static class HotKeys
{
/// <summary>
/// Method to calculate the sum of the modifier keys.
/// </summary>
/// <param name="modifierKeys"><see cref="ModifierKeys"/>.</param>
/// <returns>Sum of the calculated modifier keys.</returns>
public static int GetModifierKeysSum(ModifierKeys modifierKeys)
{
var sum = 0x0000;
if (modifierKeys.HasFlag(ModifierKeys.Alt))
sum += 0x0001;
if (modifierKeys.HasFlag(ModifierKeys.Control))
sum += 0x0002;
if (modifierKeys.HasFlag(ModifierKeys.Shift))
sum += 0x0004;
if (modifierKeys.HasFlag(ModifierKeys.Windows))
sum += 0x0008;
return sum;
}
/// <summary>
/// Method to convert WPF key to WinForms key.
/// </summary>
/// <param name="key">WPF key.</param>
/// <returns>WinForms key.</returns>
public static System.Windows.Forms.Keys WpfKeyToFormsKeys(Key key)
{
return (System.Windows.Forms.Keys)KeyInterop.VirtualKeyFromKey(key);
}
/// <summary>
/// Method to convert WinForms key to WPF key.
/// </summary>
/// <param name="keys">WinForms key.</param>
/// <returns>WPF key.</returns>
public static Key FormsKeysToWpfKey(System.Windows.Forms.Keys keys)
{
return FormsKeysToWpfKey((int)keys);
}
/// <summary>
/// Method to convert WinForms key to WPF key.
/// </summary>
/// <param name="keys">WinForms key as <see cref="int"/>.</param>
/// <returns>WPF key.</returns>
public static Key FormsKeysToWpfKey(int keys)
{
return KeyInterop.KeyFromVirtualKey(keys);
}
/// <summary>
/// Method to get modifier keys from an <see cref="int"/> value.
/// </summary>
/// <param name="modifierKeys">Modifier key as <see cref="int"/>.</param>
/// <returns>Return <see cref="ModifierKeys"/>.</returns>
public static ModifierKeys GetModifierKeysFromInt(int modifierKeys)
{
var modKeys = ModifierKeys.None;
if (modifierKeys - 0x0008 >= 0)
{
modKeys |= ModifierKeys.Windows;
modifierKeys -= 0x0008;
}
if (modifierKeys - 0x0004 >= 0)
{
modKeys |= ModifierKeys.Shift;
modifierKeys -= 0x0004;
}
if (modifierKeys - 0x0002 >= 0)
{
modKeys |= ModifierKeys.Control;
modifierKeys -= 0x0002;
}
if (modifierKeys - 0x0001 >= 0)
modKeys |= ModifierKeys.Alt;
return modKeys;
}
}
}