-
Notifications
You must be signed in to change notification settings - Fork 396
Expand file tree
/
Copy pathHotkeyBox.cs
More file actions
84 lines (69 loc) · 1.59 KB
/
HotkeyBox.cs
File metadata and controls
84 lines (69 loc) · 1.59 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
using System;
using System.ComponentModel;
using System.Linq;
using System.Windows.Forms;
using System.Windows.Forms.Design;
using ReClassNET.Input;
namespace ReClassNET.Controls
{
[Designer(typeof(HotkeyBoxDesigner))]
public partial class HotkeyBox : UserControl
{
public KeyboardInput Input { get; set; }
public KeyboardHotkey Hotkey { get; } = new KeyboardHotkey();
public HotkeyBox()
{
InitializeComponent();
DisplayHotkey();
}
protected override void SetBoundsCore(int x, int y, int width, int height, BoundsSpecified specified)
{
base.SetBoundsCore(x, y, width, 20, specified);
}
private void textBox_Enter(object sender, EventArgs e)
{
timer.Enabled = true;
}
private void textBox_Leave(object sender, EventArgs e)
{
timer.Enabled = false;
}
private void timer_Tick(object sender, EventArgs e)
{
if (Input == null)
{
return;
}
var keys = Input.GetPressedKeys();
if (keys.Length != 0)
{
foreach (var key in keys.Select(k => k & Keys.KeyCode).Where(k => k != Keys.None))
{
Hotkey.AddKey(key);
}
DisplayHotkey();
}
}
private void clearButton_Click(object sender, EventArgs e)
{
Clear();
}
private void DisplayHotkey()
{
textBox.Text = Hotkey.ToString();
}
public void Clear()
{
Hotkey.Clear();
DisplayHotkey();
}
}
internal class HotkeyBoxDesigner : ControlDesigner
{
private HotkeyBoxDesigner()
{
AutoResizeHandles = true;
}
public override SelectionRules SelectionRules => SelectionRules.LeftSizeable | SelectionRules.RightSizeable | SelectionRules.Moveable;
}
}