void synDev_OnPacket() { synDev.LoadPacket(synPacket); if (calibrateState == 0) { int X, Y; X = Clamp(Clamp(synPacket.X - XMin, XMax, 0) * wWidth / (XMax - XMin), wWidth, 0); Y = Clamp(Clamp(YMax - synPacket.Y, YMax, 0) * wHeight / (YMax - YMin), wHeight, 0); if (contacts[0].PointerInfo.PointerId == 0 && synPacket.FingerState != 0 && synPacket.X > 1 && synPacket.Y > 1) { contacts[0] = MakePointerTouchInfo(X, Y, synPacket.W, 1); //contacts[1] = MakePointerTouchInfo(650, 500, 2, 2); bool success = TouchInjector.InjectTouchInput(1, contacts); } else if (synPacket.FingerState != 0 && synPacket.X > 1 && synPacket.Y > 1) { contacts[0].PointerInfo.PtPixelLocation.X = X; contacts[0].PointerInfo.PtPixelLocation.Y = Y; contacts[0].ContactArea.left = X - synPacket.W; contacts[0].ContactArea.right = X + synPacket.W; contacts[0].ContactArea.top = Y - synPacket.W; contacts[0].ContactArea.bottom = Y + synPacket.W; contacts[0].PointerInfo.PointerFlags = PointerFlags.UPDATE | PointerFlags.INRANGE | PointerFlags.INCONTACT; //contacts[1].PointerInfo.PointerFlags = PointerFlags.UPDATE | PointerFlags.INRANGE | PointerFlags.INCONTACT; bool s = TouchInjector.InjectTouchInput(1, contacts); } else if ((contacts[0].PointerInfo.PointerFlags & PointerFlags.UP) != PointerFlags.UP) { //release them contacts[0].PointerInfo.PointerFlags = PointerFlags.UP; //contacts[1].PointerInfo.PointerFlags = PointerFlags.UP; bool success2 = TouchInjector.InjectTouchInput(1, contacts); contacts[0].PointerInfo.PointerId = 0; } touchLabel.Text = "X: " + X + ", Y: " + Y + ", W: " + synPacket.W + ", Z: " + synPacket.Z; } else { if (synPacket.FingerState != 0 && lastFingerState == 0) { switch (calibrateState) { case 1: XMin = synPacket.X; calibrateLabel.Text = "Swipe from top."; calibrateState = 2; break; case 2: YMax = synPacket.Y; calibrateLabel.Text = "Swipe from right."; calibrateState = 3; break; case 3: XMax = synPacket.X; calibrateLabel.Text = "Swipe from bottom."; calibrateState = 4; break; case 4: YMin = synPacket.Y; calibrateLabel.Text = "Done."; calibrateState = 5; Settings.Default.XMin = XMin; Settings.Default.XMax = XMax; Settings.Default.YMin = YMin; Settings.Default.YMax = YMax; Settings.Default.Save(); break; case 5: calibrateState = 0; break; } updateCalibrationStatusLabel(); } } lastFingerState = synPacket.FingerState; }
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; } }