public void StartTouchCapture() { EnsureNotDisposed(); if (_acquired) { return; } try { _device.Acquire(0); } catch (UnauthorizedAccessException ex) { // From Synaptics SDK documentation: // // The device cannot be acquired. The most likely cause is that // another program has previously acquired the device. throw new TouchCaptureException(ex); } _device.OnPacket += OnDevicePacket; _acquired = true; }
/* Event handler for Synaptics API touch events */ void SynDevCtrl_OnPacket() { SynPacketCtrl SynPacCtrl = new SynPacketCtrl(); SynDevCtrl.LoadPacket(SynPacCtrl); if (SynPacCtrl.GetLongProperty(SynPacketProperty.SP_ExtraFingerState) == 2) { isMultitouch = true; } else if (SynPacCtrl.GetLongProperty(SynPacketProperty.SP_ExtraFingerState) == 1) { isMultitouch = false; } else if (SynPacCtrl.GetLongProperty(SynPacketProperty.SP_ExtraFingerState) == 0) { isMultitouch = false; } // 8 is a "magic number" made through testing. It specifies the boundary for a "normal" finger width. // This should probably be configurable in the future. if ((SynPacCtrl.W > 8) || isMultitouch) { // Width is higher than normal. We probably have two fingers on the touchpad. // OR We actually found a native multitouch! // Disable touchpad input to the OS. // We will be exclusively handling the touchpad during these events. // Native multitouch caveat! Native two-finger scrolling WILL compete with this. // Disable it if you prever MultiTouchEnabler's scrolling. // Todo.. This is for coexisting nicely with native multitouch non-scrolling gestures. /*if (SynPacCtrl.GetLongProperty(SynPacketProperty.SP_ExtraFingerState) == 2) * { * //Check space between fingers. We don't want to interfere with other gestures... * if (SynPacCtrl.XMickeys > 5) * { * if (isExclusivityAcquired) * SynDevCtrl.Unacquire(); * isExclusivityAcquired = false; * gestureMode = 1; * } * * }*/ if (!isExclusivityAcquired && gestureMode == 0) { try { // This gives us exclusive control of the touchpad. // Other software, like the OS, will not recieve the touch events. SynDevCtrl.Acquire(0); isExclusivityAcquired = true; } catch { // This might happen sometimes. It's okay. isExclusivityAcquired = false; } } if (gestureMode == 0) { // Scroll the mouse! // Use the user-defined scroll speed factor and the inversion setting to determine the scroll amount mouse_event(2048, 0, 0, SynPacCtrl.YMickeys * scrollSpeed * scrollInversion, GetMessageExtraInfo()); } else { gestureMode = 1; } } else { // We need to relinquish exclusivity of the touchpad. if (isExclusivityAcquired) { SynDevCtrl.Unacquire(); } isExclusivityAcquired = false; } // We build up a lot of memory usage if we let this go on normally // Force the Garbage Collector to do its job! SynPacCtrl = null; GC.Collect(); GC.WaitForPendingFinalizers(); }
private void Form1_Load(object sender, EventArgs e) { try { // Get the SID of the admin group on the local machine. var localAdminGroupSid = new SecurityIdentifier( WellKnownSidType.BuiltinAdministratorsSid, null); WindowsIdentity windowsIdentity = WindowsIdentity.GetCurrent(); //Then you can check the Groups property on the WindowsIdentity of the user to see if that user is a member of the local admin group, like so: bool isLocalAdmin = windowsIdentity.Groups. Select(g => (SecurityIdentifier)g.Translate(typeof(SecurityIdentifier))). Any(s => s == localAdminGroupSid); if (isLocalAdmin) { adminButton.Visible = false; } } catch (Exception) { } synAPI.Initialize(); synAPI.Activate(); DeviceHandle = synAPI.FindDevice(SynConnectionType.SE_ConnectionAny, SynDeviceType.SE_DeviceTouchPad, -1); if (DeviceHandle == -1) { MessageBox.Show("Unable to find a Synaptics TouchPad"); } else { synDev.Select(DeviceHandle); synDev.Activate(); oldDisableState = synDev.GetLongProperty(SynDeviceProperty.SP_DisableState); synDev.SetLongProperty(SynDeviceProperty.SP_DisableState, 0); bool s = TouchInjector.InitializeTouchInjection(256, TouchFeedback.INDIRECT);//initialize with default settings Settings sett = Settings.Default; hideBox.Checked = sett.HideToTaskbar; if (sett.XMin != 0) { XMin = sett.XMin; } else { XMin = synDev.GetLongProperty(SynDeviceProperty.SP_XLoSensor); } if (sett.XMax != 0) { XMax = sett.XMax; } else { XMax = synDev.GetLongProperty(SynDeviceProperty.SP_XHiSensor); } if (sett.YMin != 0) { YMin = sett.YMin; } else { YMin = synDev.GetLongProperty(SynDeviceProperty.SP_YLoSensor); } if (sett.YMax != 0) { YMax = sett.YMax; } else { YMax = synDev.GetLongProperty(SynDeviceProperty.SP_YHiSensor); } ZTouchThreshold = synDev.GetLongProperty(SynDeviceProperty.SP_ZTouchThreshold) + 20; wHeight = GetScreen().Height - 1; wWidth = GetScreen().Width - 1; synDev.Acquire(0); updateCalibrationStatusLabel(); synDev.OnPacket += synDev_OnPacket; } }