Example #1
0
 private void InputKey_Load(object sender, EventArgs e)
 {
     if (instance != null && instance != this)
     {
         Close();
         return;
     }
     instance = this;
 }
Example #2
0
        private void grdControls_CellDoubleClick(object sender, DataGridViewCellEventArgs e)
        {
            if (grdControls.Rows[e.RowIndex] == null || grdControls.Rows[e.RowIndex].Cells[2] == null || grdControls.Rows[e.RowIndex].Cells[2].Value == null) return;
            if (grdControls.Rows[e.RowIndex].Cells[2].Value.ToString() == "Joystick")
            {
                string id = Microsoft.VisualBasic.Interaction.InputBox("Joystick ID", "Enter Joystick ID # (1 is default)", "1");
                    
                if (Byte.Parse(id) == 0)
                {
                    MessageBox.Show("Invalid ID: " + id + ", discarding");
                    return;
                }
                bool isFound = false;
                foreach (var key in config.keys)
                {
                    if (key.Index == (int)grdControls.Rows[e.RowIndex].Cells[0].Value)
                    {
                        key.KeyName = id;
                        key.KeyCode = Byte.Parse(id);
                        isFound = true;
                        break;
                    }
                }
                if (!isFound)
                {
                    MessageBox.Show("There was an error setting joystick id, try again later.");
                    return;
                }
                grdControls.Rows[e.RowIndex].Cells[4].Value = id;
                return;
            }

            lastKeyIndex = -1;
            foreach (var key in config.keys)
            {
                if (key.Index == (int)grdControls.Rows[e.RowIndex].Cells[0].Value)
                {
                    lastKeyIndex = key.Index;
                    if (inputKey == null) inputKey = new InputKey();
                    inputKey.Show();

                    InputKey.SetJoystickID(key.joystickIndex);
                    InputKey.SetKeyButton(key.KeyCode);
                    InputKey.SetType(key.Type);
                    InputKey.SetIndex(key.Index.ToString());
                    
                    this.Enabled = false;
                    return;
                }
            }
            if (lastKeyIndex == -1)
            {
                MessageBox.Show("An internal error occured");
                return;
            }
            
        }