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