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