public Touchpad()
        {
            m_api.Initialize();

            int hdev = -1;

            m_api.FindDevice((int)SYNCTRLLib.SynConnectionType.SE_ConnectionAny, (int)SYNCTRLLib.SynDeviceType.SE_DeviceTouchPad, ref hdev);
            if (hdev < 0)
            {
                MessageBox.Show("No Synaptics TouchPad device found!", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                Application.Exit();
            }
            m_dev.Select(hdev);
            m_dev.GetProperty((int)SYNCTRLLib.SynDeviceProperty.SP_XLoBorder, ref m_xMin);
            m_dev.GetProperty((int)SYNCTRLLib.SynDeviceProperty.SP_XHiBorder, ref m_xMax);
            m_dev.GetProperty((int)SYNCTRLLib.SynDeviceProperty.SP_YLoBorder, ref m_yMin);
            m_dev.GetProperty((int)SYNCTRLLib.SynDeviceProperty.SP_YHiBorder, ref m_yMax);

            // must create form (to get the sync context) before start processing events
            m_cpl = new ControlPanel(m_api, m_dev);
            m_cpl.SettingsChanged += m_cpl_SettingsChanged;

            SystemEvents.PowerModeChanged += SystemEvents_PowerModeChanged;

            m_dev.SetEventNotification(m_notifyEvent.SafeWaitHandle.DangerousGetHandle());
            ProcessTouchEvents();

#if DEBUG
            ShowControlPanel();
#endif
        }
        int GetProperty(SYNCOMLib.SynDevice dev, SYNCTRLLib.SynDeviceProperty prop)
        {
            int pValue = 0;

            dev.GetProperty((int)prop, ref pValue);
            return(pValue);
        }
        private void TmrPoll_Tick(object sender, EventArgs e)
        {
            if (!GetTouchPadStatus(m_dev, SYNCTRLLib.SynDeviceProperty.SP_DeviceStatus))
            {
                lbltouchstatus.Text       = @"Yes";
                lblusbmouse.Text          = @"No";
                cbTouchpadenabled.Checked = true;
                enableAllGUIControls(true);
            }
            else
            {
                lbltouchstatus.Text       = @"No";
                lblusbmouse.Text          = @"Yes";
                cbTouchpadenabled.Checked = false;
                enableAllGUIControls(false);
            }

            if (!GetDisableTouchpadWhenUSBMouse(m_dev, SYNCTRLLib.SynDeviceProperty.SP_DisablePDIfExtPresent))
            {
                cbDisableTP.Checked = false;
            }
            else
            {
                cbDisableTP.Checked = true;
            }

            //Synaptics tray state 17|49
            int pValue = 0;

            m_dev.GetProperty(524288, ref pValue);
            switch (pValue)
            {
            case 17:
                cbTray.Checked = true;
                break;

            case 49:
                cbTray.Checked = false;
                break;

            default:
                break;
            }
        }
        bool GetDisableTouchpadWhenUSBMouse(SYNCOMLib.SynDevice dev, SYNCTRLLib.SynDeviceProperty prop)
        {
            int pValue = 0;

            try
            {
                dev.GetProperty((int)prop, ref pValue);
                return(Convert.ToBoolean(pValue));
            }
            catch (Exception)
            {
                return(Convert.ToBoolean(pValue));
            }
        }
        bool GetTouchPadStatus(SYNCOMLib.SynDevice dev, SYNCTRLLib.SynDeviceProperty prop)
        {
            int pValue = 0;

            try
            {
                dev.GetProperty((int)prop, ref pValue);
                return(Convert.ToBoolean(pValue));
            }
            catch (Exception)
            {
                return(Convert.ToBoolean(pValue));
            }
        }
        public ControlPanel(SYNCOMLib.SynAPI api, SYNCOMLib.SynDevice device)
        {
            InitializeComponent();

            m_api = api;
            m_dev = device;

            // auto start checkbox
            using (RegistryKey run = Registry.CurrentUser.OpenSubKey(cvrun))
            {
                m_autoStart.Checked = (run.GetValue(asm.GetName().Name) != null);
            }

            // speed
            using (RegistryKey mySettings = Registry.CurrentUser.CreateSubKey(settingsKeyName))
            {
                m_scrollSpeed.Value = (int)mySettings.GetValue("ScrollSpeed", 1000);
                m_speedLabel.Text   = string.Format("{0}%", m_scrollSpeed.Value / 10);
            }

            FillComboBox(m_cbUpAction);
            FillComboBox(m_cbDownAction);
            FillComboBox(m_cbLeftAction);
            FillComboBox(m_cbRightAction);

            // gestures
            using (RegistryKey mySettings = Registry.CurrentUser.CreateSubKey(settingsKeyName))
            {
                m_cbUpAction.SelectedIndex    = (int)mySettings.GetValue("UpAction", (int)GestureAction.Flip3D);
                m_cbDownAction.SelectedIndex  = (int)mySettings.GetValue("DownAction", (int)GestureAction.ShowDesktop);
                m_cbLeftAction.SelectedIndex  = (int)mySettings.GetValue("LeftAction", (int)GestureAction.DockLeft);
                m_cbRightAction.SelectedIndex = (int)mySettings.GetValue("RightAction", (int)GestureAction.DockRight);
            }

            m_cbUpAction.SelectedIndexChanged    += gestureActionChanged;
            m_cbDownAction.SelectedIndexChanged  += gestureActionChanged;
            m_cbLeftAction.SelectedIndexChanged  += gestureActionChanged;
            m_cbRightAction.SelectedIndexChanged += gestureActionChanged;

            // api version and device version
            m_apiVer.Text         = GetSynapticAPIStringProperty(api, SYNCTRLLib.SynAPIStringProperty.SP_VersionString, 100);
            m_devName.Text        = GetSynapticDeviceStringProperty(device, SYNCTRLLib.SynDeviceStringProperty.SP_ModelString, 100);
            lbldriverversion.Text = GetVersion();

            ShowDebugElements();

            RegistryKey synTPCplKey = Registry.LocalMachine.OpenSubKey("Software\\Synaptics\\SynTPCpl", false);
            int         awUI        = Convert.ToInt32(synTPCplKey.GetValue("AlienwareUI")); // dell alienware theme..

            if (awUI == 1)
            {
                cbSkin.Checked = true;
            }
            else if (awUI == 0)
            {
                cbSkin.Checked = false;
            }
            int uiStyle = Convert.ToInt32(synTPCplKey.GetValue("UIStyle")); // win8ui

            if (uiStyle == 14)
            {
                cbUnlockHiddenScroll.Checked = false;
            }
            else if (uiStyle == 15)
            {
                cbUnlockHiddenScroll.Checked = true;
            }

            int m_touchspeed = 0;

            m_dev.GetProperty(16777884, ref m_touchspeed);
            m_PointerSpeed.Value = m_touchspeed;

            int m_touchpressure = 0;

            m_dev.GetProperty(268435752, ref m_touchpressure);
            m_Touchpressure.Value = m_touchpressure;

            int m_tappingspeed = 0;

            m_dev.GetProperty(16777531, ref m_tappingspeed);
            m_Tappingspeed.Value = m_tappingspeed;

            // 0 = none, 3 = tick to click, 7 = tick to click & touchguard
            int iGestures = 0;

            m_dev.GetProperty(268435726, ref iGestures);
            switch (iGestures)
            {
            case 0:
                m_Ticktoclick.Checked  = false;
                m_Touchgaurd.Checked   = false;
                m_Tappingspeed.Enabled = false;
                break;

            case 3:
                m_Ticktoclick.Checked  = true;
                m_Touchgaurd.Checked   = false;
                m_Tappingspeed.Enabled = true;
                break;

            case 7:
                m_Ticktoclick.Checked  = true;
                m_Touchgaurd.Checked   = true;
                m_Tappingspeed.Enabled = true;
                break;

            default:
                break;
            }

            int m_palmdetection = 0;

            m_dev.GetProperty(16777876, ref m_palmdetection);
            switch (m_palmdetection)
            {
            case 1114255:
                m_Palmdetection.Checked = true;
                m_Touchguard.Enabled    = true;
                break;

            case 1114254:
                m_Palmdetection.Checked = false;
                m_Touchguard.Enabled    = false;
                break;

            default:
                break;
            }

            //Palm sensetivity
            int m_touchguard = 0;

            m_dev.GetProperty(268435843, ref m_touchguard);
            m_Touchguard.Value = m_touchguard;

            //zigzag 16778072
            int m_zigzag = 0;

            m_dev.GetProperty(16778072, ref m_zigzag);
            m_Zigzag.Checked = Convert.ToBoolean(m_zigzag);

            int m_circularscrolling = 0;

            m_dev.GetProperty((int)SYNCTRLLib.SynDeviceProperty.SP_ChiralScrolling, ref m_circularscrolling);
            m_Circularscrolling.Checked = Convert.ToBoolean(m_circularscrolling);

            int m_disablenavinbuttuonzone = 0;

            m_dev.GetProperty((int)SYNCTRLLib.SynDeviceProperty.SP_DisableNavigationInButtonZone, ref m_disablenavinbuttuonzone);
            m_DisableNavInButtuonZone.Checked = Convert.ToBoolean(m_disablenavinbuttuonzone);

            // 0 disable, 5 slow scroll, 17 circular scroll
            int m_verticalscrollingflags = 0;

            m_dev.GetProperty((int)SYNCTRLLib.SynDeviceProperty.SP_VerticalScrollingFlags, ref m_verticalscrollingflags);
            switch (m_verticalscrollingflags)
            {
            case 0:
                m_Enableedgesrolling.Checked = false;
                //GUI controls
                m_Slowscrolling.Enabled             = false;
                m_Circularscrolling.Enabled         = false;
                m_Zoomscroll.Enabled                = false;
                m_Edgescrollspeed.Enabled           = false;
                m_Virtualscrollregionnorrow.Enabled = false;
                m_Virtualscrollregionnormal.Enabled = false;
                m_Virtualscrollregionwide.Enabled   = false;
                break;

            case 1:
                m_Enableedgesrolling.Checked = true;
                //GUI controls
                m_Slowscrolling.Enabled             = true;
                m_Circularscrolling.Enabled         = true;
                m_Zoomscroll.Enabled                = true;
                m_Edgescrollspeed.Enabled           = true;
                m_Virtualscrollregionnorrow.Enabled = true;
                m_Virtualscrollregionnormal.Enabled = true;
                m_Virtualscrollregionwide.Enabled   = true;
                break;

            case 5:
                m_Enableedgesrolling.Checked = true;
                m_Circularscrolling.Checked  = false;
                m_Slowscrolling.Checked      = true;
                break;

            case 17:
                m_Enableedgesrolling.Checked = true;
                m_Circularscrolling.Checked  = true;
                m_Slowscrolling.Checked      = true;
                break;

            default:
                break;
            }

            // 32 - 256
            int m_edgescrollspeed = 0;

            m_dev.GetProperty((int)SYNCTRLLib.SynDeviceProperty.SP_VerticalScrollSpeed, ref m_edgescrollspeed);
            m_Edgescrollspeed.Value = m_edgescrollspeed;

            // 178 narrow, 268 normal, 357 wide
            int m_edgescrollarea = 0;

            m_dev.GetProperty((int)SYNCTRLLib.SynDeviceProperty.SP_VerticalScrollRegionWidth, ref m_edgescrollarea);
            switch (m_edgescrollarea)
            {
            case 178:
                m_Virtualscrollregionnorrow.Checked = true;
                break;

            case 268:
                m_Virtualscrollregionnormal.Checked = true;
                break;

            case 357:
                m_Virtualscrollregionwide.Checked = true;
                break;

            default:
                break;
            }

            // 5120 off 5121 on
            int m_zoomscroll = 0;

            m_dev.GetProperty(2424832, ref m_zoomscroll);
            switch (m_zoomscroll)
            {
            case 5120:
                m_Zoomscroll.Checked = false;
                break;

            case 5121:
                m_Zoomscroll.Checked = true;
                break;

            default:
                break;
            }

            m_Doubleclickspeed.Value = GetDoubleClickTime();

            int m_multifingergesture = 0;

            m_dev.GetProperty(589824, ref m_multifingergesture);
            switch (m_multifingergesture)
            {
            case 1:
                m_Enable2Fgestures.Checked = false;
                m_2FPanning.Checked        = false;
                m_2Fslowscrolling.Checked  = false;
                m_2Fsueezezoom.Checked     = false;
                m_2Fturning.Checked        = false;
                break;

            case 4097:
                m_Enable2Fgestures.Checked = false;
                m_2FPanning.Checked        = false;
                m_2Fsueezezoom.Checked     = false;
                m_2Fturning.Checked        = false;
                break;

            case 4099:
                m_Enable2Fgestures.Checked = true;
                m_2FPanning.Checked        = true;
                m_2Fsueezezoom.Checked     = false;
                m_2Fturning.Checked        = false;
                //=============================
                m_2FPanning.Checked = true;
                break;

            case 4115:
                m_Enable2Fgestures.Checked = true;
                m_2FPanning.Checked        = true;
                m_2Fsueezezoom.Checked     = true;
                m_2Fturning.Checked        = false;
                //=============================
                m_2FPanning.Checked    = true;
                m_2Fsueezezoom.Checked = true;
                break;

            case 4107:
                m_Enable2Fgestures.Checked = true;
                m_2FPanning.Checked        = true;
                m_2Fsueezezoom.Checked     = false;
                m_2Fturning.Checked        = true;
                //=============================
                m_2FPanning.Checked = true;
                m_2Fturning.Checked = true;
                break;

            case 4123:
                m_Enable2Fgestures.Checked = true;
                m_2FPanning.Checked        = true;
                m_2Fsueezezoom.Checked     = true;
                m_2Fturning.Checked        = true;
                //=============================
                m_2FPanning.Checked    = true;
                m_2Fsueezezoom.Checked = true;
                m_2Fturning.Checked    = true;
                break;

            case 4113:
                m_Enable2Fgestures.Checked = true;
                m_2FPanning.Checked        = false;
                m_2Fsueezezoom.Checked     = true;
                m_2Fturning.Checked        = false;
                //=============================
                m_2Fsueezezoom.Checked = true;
                break;

            case 4105:
                m_Enable2Fgestures.Checked = true;
                m_2FPanning.Checked        = false;
                m_2Fsueezezoom.Checked     = false;
                m_2Fturning.Checked        = true;
                //=============================
                m_2Fturning.Checked = true;
                break;

            case 4121:
                m_Enable2Fgestures.Checked = true;
                m_2FPanning.Checked        = false;
                m_2Fsueezezoom.Checked     = true;
                m_2Fturning.Checked        = true;
                //=============================
                m_2Fsueezezoom.Checked = true;
                m_2Fturning.Checked    = true;
                break;

            default:
                break;
            }

            // 32 - 256
            int m_panscrollspeed = 0;

            m_dev.GetProperty(268435847, ref m_panscrollspeed);
            m_Panscrollspeed.Value = m_panscrollspeed;

            //1 = off, 5 = on spid 268435845
            int m_2fslowscrolling = 0;

            m_dev.GetProperty((int)SYNCTRLLib.SynDeviceProperty.SP_2FHorizontalScrollingFlags, ref m_2fslowscrolling);
            switch (m_2fslowscrolling)
            {
            case 1:
                m_2Fslowscrolling.Checked = false;
                break;

            case 5:
                m_2Fslowscrolling.Checked = true;
                break;

            default:
                break;
            }
        }