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