private void button1_KeyUp(object sender, KeyEventArgs e)
        {
            ControlMappingButton SenderButton = sender as ControlMappingButton;

            buttonControlMappingSave.Focus(); //remove focus
            //ReAdd events
            SenderButton.KeyUp -= button1_KeyUp;
            SenderButton.Click += buttonGetKeyCode_Click;
            ProcessKeyDetection(SenderButton);
        }
        private void CreateFormControls()
        {
            localControlMapping = new Dictionary <string, short[]>(Main_Form.server.pcController.ControlMapping);
            List <string> keyList = new List <string>(localControlMapping.Keys);
            int           row     = 0;
            //Sorting controls between Pages and top-down
            Dictionary <string, string[]> ControlsGroups = new Dictionary <string, string[]>();

            ControlsGroups.Add("Truck", new string[] { "Throttle", "Brake", "ParkingBrake", "LeftIndicator", "RightIndicator", "HazardLight", "LightModes", "HighBeam", "AirHorn", "Horn", "CruiseControl" });
            ControlsGroups.Add("Hud", new string[] {  });
            ControlsGroups.Add("Camera", new string[] {  });
            ControlsGroups.Add("Other", new string[] {  });
            //Labels
            Dictionary <string, string> labelsList = new Dictionary <string, string>();

            labelsList.Add("Throttle", "Throttle");
            labelsList.Add("Brake", "Brake / Revers");
            labelsList.Add("ParkingBrake", "Parking Brake");
            labelsList.Add("LeftIndicator", "Left-Turn Indicator");
            labelsList.Add("RightIndicator", "Right-Turn Indicator");
            labelsList.Add("HazardLight", "Hazard Warning");
            labelsList.Add("LightModes", "Light Modes");
            labelsList.Add("HighBeam", "High Beam Headlights");
            labelsList.Add("AirHorn", "Air Horn");
            labelsList.Add("Horn", "Horn");
            labelsList.Add("CruiseControl", "Cruise Control");


            foreach (TabPage tempTab in tabControlControlSections.TabPages)
            {
                string PageName = tempTab.Name.Substring(7, tempTab.Name.Length - 7);
                //Create Table layout
                TableLayoutPanel tempTableLayout = new TableLayoutPanel();
                tempTableLayout.Name        = "tableLayoutPanelControls" + PageName;
                tempTableLayout.AutoScroll  = true;
                tempTableLayout.ColumnCount = 2;
                tempTableLayout.ColumnStyles.Add(new ColumnStyle(SizeType.Absolute, 150F));
                tempTableLayout.ColumnStyles.Add(new ColumnStyle(SizeType.Percent, 100F));
                tempTableLayout.Dock = DockStyle.Fill;
                tempTab.Controls.Add(tempTableLayout);
                //
                if (ControlsGroups[PageName].Length > 0)
                {
                    foreach (string Key in ControlsGroups[PageName])
                    {
                        tempTableLayout.RowStyles.Add(new RowStyle(SizeType.Absolute, 25F));
                        //Create label
                        Label tempLabel = new Label();
                        tempLabel.Name = "label" + Key;
                        tempLabel.Text = labelsList[Key];
                        tempTableLayout.Controls.Add(tempLabel, 0, row);

                        //Creating Button
                        ControlMappingButton tempButton = new ControlMappingButton();
                        tempButton.Text   = "New";
                        tempButton.Name   = "button" + Key;
                        tempButton.Text   = row.ToString();
                        tempButton.Dock   = DockStyle.Fill;
                        tempButton.Margin = new Padding(0);
                        //Actions
                        tempButton.Click += buttonGetKeyCode_Click;

                        tempTableLayout.Controls.Add(tempButton, 1, row); //Add

                        row++;
                    }
                    tempTableLayout.RowStyles.Add(new RowStyle(SizeType.Percent, 100F)); //Extra row for looks
                    tempTableLayout.RowCount = ++row;
                }
            }
        }
        private void ProcessKeyDetection(ControlMappingButton _inputButton)
        {
            string buttonName = _inputButton.Name.Substring(6);

            SetKey(buttonName, _inputButton.ScanCodes);
        }