private void StartMapKey()
        {
            keyUpCommands.Text = string.Empty;
            keyDownCommands.Text = string.Empty;

            AcceptCommand.Enabled = false;
            RepeatCommand.Enabled = false;
            CancelCommand.Enabled = false;

            PressAndRelease.Visible = true;

            _newKey = new Key(_keyName);

            _keyManager.KeyStrokeReceivedEvent += ListenKeyboard;
            _keyManager.ListenKeyBoard();
        }
        private void UpdateKeyNode(Key key, string oldKeyName)
        {
            TreeNode treeNode = treeKeys.Nodes.OfType<TreeNode>().Where(k => k.Name.Equals(oldKeyName, StringComparison.CurrentCultureIgnoreCase)).SingleOrDefault();

            bool wasSelected = treeNode.IsSelected;
            bool wasExpanded = treeNode.IsExpanded;

            var oldIndex = treeNode.Index;
            treeNode = BuildNodeFromKey(key);

            if (wasExpanded) treeNode.Expand();

            treeKeys.Nodes.RemoveAt(oldIndex);
            treeKeys.Nodes.Insert(oldIndex, treeNode);
            if (wasSelected)
            {
                treeKeys.SelectedNode = treeNode;
            }
        }
        private void AddKeyNode(Key key)
        {
            TreeNode treeNode = BuildNodeFromKey(key);

            //treeNode.Expand();
            treeKeys.Nodes.Add(treeNode);
        }
        private static TreeNode BuildNodeFromKey(Key key)
        {
            var treeNode = new TreeNode(key.Name)
                                    {
                                        Name = key.Name,
                                        Text = string.Format("{0}{1}", key.Name, string.IsNullOrEmpty(key.InfoWindowsKeys) ? string.Empty : string.Format("      Description: {0}", key.InfoWindowsKeys))
                                    };

            var treeDown = new TreeNode("Pressed")
                               {
                                   Name = key.Name + "_Down"
                               };
            treeDown.Expand();

            for (int i = 0; i < key.KeyDownStrokes.Count; i++)
            {
                var treeKeyStroke = new TreeNode(key.KeyDownStrokes[i].ToString());
                treeKeyStroke.Name = key.Name + "_Down" + i.ToString("00");
                treeDown.Nodes.Add(treeKeyStroke);
            }
            treeNode.Nodes.Add(treeDown);

            var treeUp = new TreeNode("Released")
                             {
                                 Name = key.Name + "_Up"
                             };
            treeUp.Expand();

            for (int i = 0; i < key.KeyUpStrokes.Count; i++)
            {
                var treeKeyStroke = new TreeNode(key.KeyUpStrokes[i].ToString());
                treeKeyStroke.Name = key.Name + "_Up" + i.ToString("00");
                treeUp.Nodes.Add(treeKeyStroke);
            }
            treeNode.Nodes.Add(treeUp);

            return treeNode;
        }