annotate SetHotkey.cs @ 0:aca8706f4eec default tip

Initial commit
author Brad Greco <brad@bgreco.net>
date Mon, 13 Oct 2014 21:28:19 -0500
parents
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
aca8706f4eec Initial commit
Brad Greco <brad@bgreco.net>
parents:
diff changeset
1 using System;
aca8706f4eec Initial commit
Brad Greco <brad@bgreco.net>
parents:
diff changeset
2 using System.Collections.Generic;
aca8706f4eec Initial commit
Brad Greco <brad@bgreco.net>
parents:
diff changeset
3 using System.ComponentModel;
aca8706f4eec Initial commit
Brad Greco <brad@bgreco.net>
parents:
diff changeset
4 using System.Data;
aca8706f4eec Initial commit
Brad Greco <brad@bgreco.net>
parents:
diff changeset
5 using System.Drawing;
aca8706f4eec Initial commit
Brad Greco <brad@bgreco.net>
parents:
diff changeset
6 using System.Text;
aca8706f4eec Initial commit
Brad Greco <brad@bgreco.net>
parents:
diff changeset
7 using System.Windows.Forms;
aca8706f4eec Initial commit
Brad Greco <brad@bgreco.net>
parents:
diff changeset
8
aca8706f4eec Initial commit
Brad Greco <brad@bgreco.net>
parents:
diff changeset
9 /*
aca8706f4eec Initial commit
Brad Greco <brad@bgreco.net>
parents:
diff changeset
10 * Copyright (c) 2014 Brad Greco <brad@bgreco.net>
aca8706f4eec Initial commit
Brad Greco <brad@bgreco.net>
parents:
diff changeset
11 */
aca8706f4eec Initial commit
Brad Greco <brad@bgreco.net>
parents:
diff changeset
12 namespace QuickQR
aca8706f4eec Initial commit
Brad Greco <brad@bgreco.net>
parents:
diff changeset
13 {
aca8706f4eec Initial commit
Brad Greco <brad@bgreco.net>
parents:
diff changeset
14 public partial class SetHotkey : Form
aca8706f4eec Initial commit
Brad Greco <brad@bgreco.net>
parents:
diff changeset
15 {
aca8706f4eec Initial commit
Brad Greco <brad@bgreco.net>
parents:
diff changeset
16 private bool capturing = false;
aca8706f4eec Initial commit
Brad Greco <brad@bgreco.net>
parents:
diff changeset
17 public KeyBinding keyBinding;
aca8706f4eec Initial commit
Brad Greco <brad@bgreco.net>
parents:
diff changeset
18
aca8706f4eec Initial commit
Brad Greco <brad@bgreco.net>
parents:
diff changeset
19 public SetHotkey(KeyBinding keyBinding)
aca8706f4eec Initial commit
Brad Greco <brad@bgreco.net>
parents:
diff changeset
20 {
aca8706f4eec Initial commit
Brad Greco <brad@bgreco.net>
parents:
diff changeset
21 InitializeComponent();
aca8706f4eec Initial commit
Brad Greco <brad@bgreco.net>
parents:
diff changeset
22 this.keyBinding = new KeyBinding();
aca8706f4eec Initial commit
Brad Greco <brad@bgreco.net>
parents:
diff changeset
23 hotkeyLabel.Text = keyBinding.toString();
aca8706f4eec Initial commit
Brad Greco <brad@bgreco.net>
parents:
diff changeset
24 }
aca8706f4eec Initial commit
Brad Greco <brad@bgreco.net>
parents:
diff changeset
25
aca8706f4eec Initial commit
Brad Greco <brad@bgreco.net>
parents:
diff changeset
26 private void captureButton_Click(object sender, EventArgs e)
aca8706f4eec Initial commit
Brad Greco <brad@bgreco.net>
parents:
diff changeset
27 {
aca8706f4eec Initial commit
Brad Greco <brad@bgreco.net>
parents:
diff changeset
28 capturing = true;
aca8706f4eec Initial commit
Brad Greco <brad@bgreco.net>
parents:
diff changeset
29 hotkeyLabel.Text = "Waiting... (ESC to clear)";
aca8706f4eec Initial commit
Brad Greco <brad@bgreco.net>
parents:
diff changeset
30 keyBinding.Win = false;
aca8706f4eec Initial commit
Brad Greco <brad@bgreco.net>
parents:
diff changeset
31 }
aca8706f4eec Initial commit
Brad Greco <brad@bgreco.net>
parents:
diff changeset
32
aca8706f4eec Initial commit
Brad Greco <brad@bgreco.net>
parents:
diff changeset
33 private void SetHotkey_KeyDown(object sender, KeyEventArgs e)
aca8706f4eec Initial commit
Brad Greco <brad@bgreco.net>
parents:
diff changeset
34 {
aca8706f4eec Initial commit
Brad Greco <brad@bgreco.net>
parents:
diff changeset
35 if (capturing && e.KeyCode == Keys.Escape)
aca8706f4eec Initial commit
Brad Greco <brad@bgreco.net>
parents:
diff changeset
36 {
aca8706f4eec Initial commit
Brad Greco <brad@bgreco.net>
parents:
diff changeset
37 capturing = false;
aca8706f4eec Initial commit
Brad Greco <brad@bgreco.net>
parents:
diff changeset
38 keyBinding.key = 0;
aca8706f4eec Initial commit
Brad Greco <brad@bgreco.net>
parents:
diff changeset
39 keyBinding.keyChar = "";
aca8706f4eec Initial commit
Brad Greco <brad@bgreco.net>
parents:
diff changeset
40 hotkeyLabel.Text = keyBinding.comboString();
aca8706f4eec Initial commit
Brad Greco <brad@bgreco.net>
parents:
diff changeset
41 }
aca8706f4eec Initial commit
Brad Greco <brad@bgreco.net>
parents:
diff changeset
42 else if (capturing && (e.KeyCode == Keys.LWin || e.KeyCode == Keys.RWin))
aca8706f4eec Initial commit
Brad Greco <brad@bgreco.net>
parents:
diff changeset
43 {
aca8706f4eec Initial commit
Brad Greco <brad@bgreco.net>
parents:
diff changeset
44 keyBinding.Win = true;
aca8706f4eec Initial commit
Brad Greco <brad@bgreco.net>
parents:
diff changeset
45 }
aca8706f4eec Initial commit
Brad Greco <brad@bgreco.net>
parents:
diff changeset
46 else if (capturing && e.KeyCode != Keys.ShiftKey && e.KeyCode != Keys.Menu && e.KeyCode != Keys.Alt && e.KeyCode != Keys.ControlKey)
aca8706f4eec Initial commit
Brad Greco <brad@bgreco.net>
parents:
diff changeset
47 {
aca8706f4eec Initial commit
Brad Greco <brad@bgreco.net>
parents:
diff changeset
48 keyBinding.key = (int)e.KeyCode;
aca8706f4eec Initial commit
Brad Greco <brad@bgreco.net>
parents:
diff changeset
49 keyBinding.keyChar = e.KeyCode.ToString();
aca8706f4eec Initial commit
Brad Greco <brad@bgreco.net>
parents:
diff changeset
50 keyBinding.Shift = e.Shift;
aca8706f4eec Initial commit
Brad Greco <brad@bgreco.net>
parents:
diff changeset
51 keyBinding.Alt = e.Alt;
aca8706f4eec Initial commit
Brad Greco <brad@bgreco.net>
parents:
diff changeset
52 keyBinding.Ctrl = e.Control;
aca8706f4eec Initial commit
Brad Greco <brad@bgreco.net>
parents:
diff changeset
53 hotkeyLabel.Text = keyBinding.toString();
aca8706f4eec Initial commit
Brad Greco <brad@bgreco.net>
parents:
diff changeset
54 }
aca8706f4eec Initial commit
Brad Greco <brad@bgreco.net>
parents:
diff changeset
55 }
aca8706f4eec Initial commit
Brad Greco <brad@bgreco.net>
parents:
diff changeset
56
aca8706f4eec Initial commit
Brad Greco <brad@bgreco.net>
parents:
diff changeset
57 private void SetHotkey_KeyUp(object sender, KeyEventArgs e)
aca8706f4eec Initial commit
Brad Greco <brad@bgreco.net>
parents:
diff changeset
58 {
aca8706f4eec Initial commit
Brad Greco <brad@bgreco.net>
parents:
diff changeset
59 if (capturing && (e.KeyCode == Keys.LWin || e.KeyCode == Keys.RWin))
aca8706f4eec Initial commit
Brad Greco <brad@bgreco.net>
parents:
diff changeset
60 {
aca8706f4eec Initial commit
Brad Greco <brad@bgreco.net>
parents:
diff changeset
61 keyBinding.Win = false;
aca8706f4eec Initial commit
Brad Greco <brad@bgreco.net>
parents:
diff changeset
62 }
aca8706f4eec Initial commit
Brad Greco <brad@bgreco.net>
parents:
diff changeset
63 else if (capturing && e.KeyCode != Keys.ShiftKey && e.KeyCode != Keys.Menu && e.KeyCode != Keys.Alt && e.KeyCode != Keys.ControlKey)
aca8706f4eec Initial commit
Brad Greco <brad@bgreco.net>
parents:
diff changeset
64 {
aca8706f4eec Initial commit
Brad Greco <brad@bgreco.net>
parents:
diff changeset
65 capturing = false;
aca8706f4eec Initial commit
Brad Greco <brad@bgreco.net>
parents:
diff changeset
66 }
aca8706f4eec Initial commit
Brad Greco <brad@bgreco.net>
parents:
diff changeset
67 okButton.Enabled = !capturing;
aca8706f4eec Initial commit
Brad Greco <brad@bgreco.net>
parents:
diff changeset
68 }
aca8706f4eec Initial commit
Brad Greco <brad@bgreco.net>
parents:
diff changeset
69
aca8706f4eec Initial commit
Brad Greco <brad@bgreco.net>
parents:
diff changeset
70 protected override bool ProcessCmdKey(ref Message msg, Keys keyData)
aca8706f4eec Initial commit
Brad Greco <brad@bgreco.net>
parents:
diff changeset
71 {
aca8706f4eec Initial commit
Brad Greco <brad@bgreco.net>
parents:
diff changeset
72 if (keyData == Keys.Escape && capturing)
aca8706f4eec Initial commit
Brad Greco <brad@bgreco.net>
parents:
diff changeset
73 {
aca8706f4eec Initial commit
Brad Greco <brad@bgreco.net>
parents:
diff changeset
74 keyBinding.key = 0;
aca8706f4eec Initial commit
Brad Greco <brad@bgreco.net>
parents:
diff changeset
75 hotkeyLabel.Text = keyBinding.toString();
aca8706f4eec Initial commit
Brad Greco <brad@bgreco.net>
parents:
diff changeset
76 capturing = false;
aca8706f4eec Initial commit
Brad Greco <brad@bgreco.net>
parents:
diff changeset
77 okButton.Enabled = true;
aca8706f4eec Initial commit
Brad Greco <brad@bgreco.net>
parents:
diff changeset
78 return true;
aca8706f4eec Initial commit
Brad Greco <brad@bgreco.net>
parents:
diff changeset
79 }
aca8706f4eec Initial commit
Brad Greco <brad@bgreco.net>
parents:
diff changeset
80 return base.ProcessCmdKey(ref msg, keyData);
aca8706f4eec Initial commit
Brad Greco <brad@bgreco.net>
parents:
diff changeset
81 }
aca8706f4eec Initial commit
Brad Greco <brad@bgreco.net>
parents:
diff changeset
82 }
aca8706f4eec Initial commit
Brad Greco <brad@bgreco.net>
parents:
diff changeset
83 }