misu – Blame information for rev 4
?pathlinks?
Rev | Author | Line No. | Line |
---|---|---|---|
1 | office | 1 | using System; |
2 | using System.Collections.Generic; |
||
3 | using System.Drawing; |
||
4 | using System.Linq; |
||
5 | using System.Windows.Forms; |
||
6 | using Configuration; |
||
7 | using Gma.System.MouseKeyHook; |
||
8 | |||
9 | namespace misu |
||
10 | { |
||
11 | public partial class BindKeyForm : Form |
||
12 | { |
||
13 | #region Public Events & Delegates |
||
14 | |||
15 | public event EventHandler<KeyBoundEventArgs> KeyBound; |
||
16 | |||
17 | #endregion |
||
18 | |||
19 | #region Public Enums, Properties and Fields |
||
20 | |||
21 | public Settings Settings { get; set; } |
||
22 | |||
23 | #endregion |
||
24 | |||
25 | #region Private Delegates, Events, Enums, Properties, Indexers and Fields |
||
26 | |||
27 | private IKeyboardMouseEvents GlobalHook { get; } |
||
28 | |||
29 | private List<Keys> BoundKeys { get; } = new List<Keys>(); |
||
30 | |||
31 | #endregion |
||
32 | |||
33 | #region Constructors, Destructors and Finalizers |
||
34 | |||
35 | public BindKeyForm() |
||
36 | { |
||
37 | InitializeComponent(); |
||
38 | } |
||
39 | |||
40 | public BindKeyForm(IKeyboardMouseEvents globalHook) : this() |
||
41 | { |
||
42 | GlobalHook = globalHook; |
||
43 | } |
||
44 | |||
45 | public BindKeyForm(IKeyboardMouseEvents globalHook, Settings settings) : this(globalHook) |
||
46 | { |
||
47 | Settings = settings; |
||
48 | } |
||
49 | |||
50 | #endregion |
||
51 | |||
52 | #region Event Handlers |
||
53 | |||
54 | private void GlobalHook_KeyUp(object sender, KeyEventArgs e) |
||
55 | { |
||
56 | GlobalHook.KeyDown -= GlobalHook_KeyDown; |
||
57 | GlobalHook.KeyUp -= GlobalHook_KeyUp; |
||
58 | |||
59 | button1.BackColor = SystemColors.Control; |
||
60 | |||
61 | e.Handled = true; |
||
62 | e.SuppressKeyPress = true; |
||
63 | |||
64 | var distinct = new List<Keys>(BoundKeys.Distinct()); |
||
65 | |||
66 | Settings.Binding.Keys = distinct; |
||
67 | |||
68 | this.Execute(() => { textBox1.Text = Settings.Binding.ToString(); }); |
||
69 | |||
70 | KeyBound?.Invoke(this, new KeyBoundEventArgs(Settings.Binding)); |
||
71 | |||
72 | BoundKeys.Clear(); |
||
73 | } |
||
74 | |||
75 | private void GlobalHook_KeyDown(object sender, KeyEventArgs e) |
||
76 | { |
||
77 | e.SuppressKeyPress = true; |
||
78 | |||
79 | BoundKeys.Add(e.KeyCode); |
||
80 | } |
||
81 | |||
82 | private void OnFormClosing(object sender, FormClosingEventArgs e) |
||
83 | { |
||
84 | GlobalHook.KeyDown -= GlobalHook_KeyDown; |
||
85 | GlobalHook.KeyUp -= GlobalHook_KeyUp; |
||
86 | } |
||
87 | |||
88 | private void RecButtonOnClick(object sender, EventArgs e) |
||
89 | { |
||
90 | button1.BackColor = Color.Red; |
||
91 | |||
92 | GlobalHook.KeyDown += GlobalHook_KeyDown; |
||
93 | GlobalHook.KeyUp += GlobalHook_KeyUp; |
||
94 | } |
||
95 | |||
96 | private void OnFormLoad(object sender, EventArgs e) |
||
97 | { |
||
98 | textBox1.Text = Settings.Binding.ToString(); |
||
99 | } |
||
100 | |||
101 | #endregion |
||
102 | } |
||
103 | } |