示例#1
0
        /*
         * Initializes form values upon load and loads previous settings
         * into UI, if available. If not, settings are initialized to
         * defaults.
         */
        private void FrmMain_Load(object sender, EventArgs e)
        {
            // get UI button references
            uiButtons = new Button[7];

            uiButtons[0] = btnJoystick;
            uiButtons[1] = btnButton1;
            uiButtons[2] = btnButton2;
            uiButtons[3] = btnButton3;
            uiButtons[4] = btnButton4;
            uiButtons[5] = btnButton5;
            uiButtons[6] = btnButton6;

            // scroll wheel event handlers so the scroll wheel cannot control the trackbars in joystick view
            trkJoystick.MouseWheel += new MouseEventHandler(trackBar_MouseWheel);
            trkCursor.MouseWheel   += new MouseEventHandler(trackBar_MouseWheel);

            // load settings
            settings       = DeviceSettings.Instance;
            buttonSettings = new ButtonSetting[6];

            // if previous settings were loaded, update the UI to reflect them
            if (settings.LoadedPreviousSession)
            {
                buttonSettings[0] = settings.GetButtonSetting(1);
                buttonSettings[1] = settings.GetButtonSetting(2);
                buttonSettings[2] = settings.GetButtonSetting(3);
                buttonSettings[3] = settings.GetButtonSetting(4);
                buttonSettings[4] = settings.GetButtonSetting(5);
                buttonSettings[5] = settings.GetButtonSetting(6);

                currentJoystickSetting = settings.JoystickSetting;
                currentJoystickSetting.AssignedButton = uiButtons[0];

                for (int i = 0; i < 6; i++)
                {
                    buttonSettings[i].AssignedButton = uiButtons[i + 1];
                }

                mnuStartWithWindows.Checked = settings.RunAtStartup;
                trayNotifShown = true;
            }
            else // set default values if not
            {
                currentJoystickSetting   = new JoystickSetting(uiButtons[0]);
                settings.JoystickSetting = currentJoystickSetting;
                for (int i = 0; i < 6; i++)
                {
                    buttonSettings[i] = new ButtonSetting(uiButtons[i + 1]);
                    settings.SetButtonSetting(i + 1, buttonSettings[i]);
                }

                trayNotifShown = false;

                // since we don't know if the application is to run at startup
                // from device settings since a previous session was not loaded,
                // check if the task exists and update device settings accordingly
                using (TaskService scheduler = new TaskService())
                {
                    if (scheduler.GetTask("Custom Mouse Controller") == null)
                    {
                        settings.RunAtStartup       = false;
                        mnuStartWithWindows.Checked = false;
                    }
                    else
                    {
                        settings.RunAtStartup       = true;
                        mnuStartWithWindows.Checked = true;
                    }
                }
            }

            //show warning if programs assigned last session have not been found
            if (settings.NotAllProgramsLoaded)
            {
                MessageBox.Show(this, "One or more programs that were assigned to the buttons have been uninstalled or moved since " +
                                "last run. Their assignments have been removed.", "Custom Mouse Controller - Missing Programs", MessageBoxButtons.OK, MessageBoxIcon.Information);
                if (Visible)
                {
                    Focus();
                }
            }

            // start out on joystick view since it is the first button
            btnJoystick.PerformClick();
            isJoystickView = true;
        }
示例#2
0
 /*
  * Main constructor that should only be accessed from within
  * this class itself if an instance of the class has not already
  * been created. Instantiates the class and saves the reference
  * to the instance of DeviceSettings.
  */
 private HardwareListener()
 {
     settings = DeviceSettings.Instance;
 }