private void ConfigEditDialog_KeyDown(object sender, KeyEventArgs e)
 {
     if (e.KeyCode == Keys.Escape && controllerThread != null && controllerThread.IsAlive)
     {
         controllerThread.Abort();
         inputDevice.Unacquire();
         inputDevice.SetNotification(null);
         ControllerConfigInternal config = controllerConfig[controllerConfigSelect.SelectedIndex];
         buttonControls[currentAction].Text = config.Buttons[currentAction] == -1
                                 ? "Unassigned"
                                 : "Button " + (config.Buttons[currentAction] + 1);
         Enabled = true;
     }
 }
 private void controllerConfigSelect_SelectedIndexChanged(object sender, EventArgs e)
 {
     if (controllerConfigSelect.SelectedIndex == -1)
     {
         controllerConfigRemove.Enabled = controllerConfigName.Enabled = false;
         foreach (ButtonControl control in buttonControls)
         {
             control.Enabled = false;
         }
     }
     else
     {
         controllerConfigRemove.Enabled = controllerConfigName.Enabled = true;
         ControllerConfigInternal config = controllerConfig[controllerConfigSelect.SelectedIndex];
         controllerConfigName.Text = config.Name;
         for (int i = 0; i < buttonControls.Count; i++)
         {
             buttonControls[i].Enabled = true;
             buttonControls[i].Text    = config.Buttons[i] == -1 ? "Unassigned" : "Button " + (config.Buttons[i] + 1);
         }
     }
 }
        void ButtonPressed(int button)
        {
            ControllerConfigInternal config = controllerConfig[controllerConfigSelect.SelectedIndex];

            if (button != -1)
            {
                if (Array.IndexOf(config.Buttons, button) != -1)
                {
                    int i = Array.IndexOf(config.Buttons, button);
                    buttonControls[i].Text = "Unassigned";
                    config.Buttons[i]      = -1;
                }
                buttonControls[currentAction].Text = "Button " + (button + 1);
                config.Buttons[currentAction]      = button;
            }
            else
            {
                buttonControls[currentAction].Text = config.Buttons[currentAction] == -1
                                        ? "Unassigned"
                                        : "Button " + (config.Buttons[currentAction] + 1);
            }
            Enabled = true;
        }