static void Main() { Controller controller = new Controller(); LeapListener listener = new LeapListener(); controller.AddListener(listener); controller.SetPolicyFlags(Controller.PolicyFlag.POLICYBACKGROUNDFRAMES); TouchInjector.InitializeTouchInjection(256, TouchFeedback.INDIRECT); //initialize touch injection with num max touch points, indirect feedback to show hover position TouchActions.InitializeContacts(); Application.EnableVisualStyles(); Application.SetCompatibleTextRenderingDefault(false); Application.Run(new SettingsWindow()); controller.RemoveListener(listener); controller.Dispose(); }
public void Init() { this.registeredTouches = new Dictionary <uint, PointerTouchInfo>(); this.injectedIds = new HashSet <uint>(); #if DEBUG this.debuginfo = new StringBuilder(); #endif this.touch.PointerInfo.pointerType = PointerInputType.TOUCH; this.touch.Orientation = 90; this.touch.Pressure = 32000; this.touch.TouchMasks = TouchMask.CONTACTAREA | TouchMask.ORIENTATION | TouchMask.PRESSURE; System.Diagnostics.Debug.Write($"{DateTime.Now}: Create native window with handle... "); this.window = new NativeWindow(); this.window.CreateHandle(new CreateParams()); System.Diagnostics.Debug.WriteLine($"[OK]"); // Create a target for surface input System.Diagnostics.Debug.Write($"{DateTime.Now}: Create contact target... "); this.ContactTarget = new ContactTarget(IntPtr.Zero, EventThreadChoice.OnBackgroundThread); this.ContactTarget.EnableInput(); System.Diagnostics.Debug.WriteLine($"[OK]"); // Init the InputSimulator System.Diagnostics.Debug.Write($"{DateTime.Now}: Init input simulatOr... "); this.inputSimulator = new InputSimulator(); System.Diagnostics.Debug.WriteLine($"[OK]"); // Initialize the TouchInjector System.Diagnostics.Debug.Write($"{DateTime.Now}: Init touch injector... "); bool s = TouchInjector.InitializeTouchInjection(NumberOfSimultaniousTouches, TouchFeedback.DEFAULT); if (s) { System.Diagnostics.Debug.WriteLine($"[OK]"); } else { System.Diagnostics.Debug.WriteLine($"[FAILED]"); return; } // Setup event handlers this.InitEventHandlers(); }
public MainWindow() { InitializeComponent(); // READ SETTINGS _settings = new ControllerSettings(); _settings.UpdateScreenValues(); SetCurrentSettings(); TouchInjector.InitializeTouchInjection(); _inputSimulator = new InputSimulator(); _gameController = new GameController(new Controller(UserIndex.One), _settings, _inputSimulator); if (_gameController.IsConnected()) { double msPerSecond = 1000; var msPerFrameRefresh = msPerSecond / _settings.refresh_rate; var timer = Observable.Interval(TimeSpan.FromMilliseconds(msPerFrameRefresh)); timer // .DoWhile(_gameController.IsConnected) .Subscribe(_ => { if (_gameController.IsConnected()) { _gameController.Poll(); } }); } else { MessageBox.Show("No controller detected, closing..."); Close(); } // CompositionTarget.Rendering += _gameController.CompositionTarget_Rendering; SystemEvents.DisplaySettingsChanged += SystemEvents_DisplaySettingsChanged; }
static void Main() { ControllerData.plugin.Start(); // Start the Hydra plugin ControllerData.controller.Add(new HydraPluginGlobal(0, ControllerData.plugin)); ControllerData.controller.Add(new HydraPluginGlobal(1, ControllerData.plugin)); TouchInjector.InitializeTouchInjection(256, TouchFeedback.INDIRECT); //initialize touch injection with num max touch points, indirect feedback to show hover position TouchActions.InitializeContacts(); Application.EnableVisualStyles(); Application.SetCompatibleTextRenderingDefault(false); //Task Settings = Task.Factory.StartNew(() => Application.Run(new SettingsWindow())); //Task InjectTouch = Task.Factory.StartNew(() => TouchActions.Run()); //Task.WaitAll(Settings, InjectTouch); Application.Run(new SettingsWindow()); }
void HandleTouchMove() { if (!isTouching) { return; } touch.PointerInfo.PtPixelLocation.X = _screenObject.Bounds.Left + (int)Math.Round((double)eventData.data.mouse.x); touch.PointerInfo.PtPixelLocation.Y = _screenObject.Bounds.Bottom - ((int)Math.Round((double)eventData.data.mouse.y) + touchYOffset); touch.PointerInfo.PointerFlags = PointerFlags.UPDATE | PointerFlags.INCONTACT | PointerFlags.INRANGE; VRControllerState_t cState = new VRControllerState_t(); OpenVR.System.GetControllerState(OpenVR.Overlay.GetPrimaryDashboardDevice(), ref cState, cStateSize); if (!TouchInjector.InjectTouchInput(1, new PointerTouchInfo[] { touch })) { Logger.Warning("[DESKTOP] Failed to inject touch move: " + GetLastError()); } }
public bool TouchDown() { if (updated) { return(false); } updated = true; touchDown = true; pointerInfo.PointerFlags = PointerFlags.INRANGE | PointerFlags.DOWN | PointerFlags.INCONTACT; pointerInfo.PtPixelLocation.X = contactX; pointerInfo.PtPixelLocation.Y = contactY; downX = contactX; downY = contactY; touchInfo.PointerInfo = pointerInfo; touches[0] = touchInfo; return(TouchInjector.InjectTouchInput(touches.Length, touches)); }
public static void AddToActiveDrag(Point point) { if (!isDragging) { return; } //Point moveAmt = new Point(previousPoint.X - point.X, previousPoint.Y - point.Y); //Update flag so we can move it activeContacts[0].PointerInfo.PointerFlags = PointerFlags.UPDATE | PointerFlags.INRANGE | PointerFlags.INCONTACT; activeContacts[0].Move(point.X - previousPoint.X, point.Y - previousPoint.Y); TouchInjector.InjectTouchInput(activeContacts.Length, activeContacts); previousPoint = point; }
void HandleTouchDown() { if (isTouching) { ReleaseTouch(); } VRControllerState_t cState = new VRControllerState_t(); OpenVR.System.GetControllerState(OpenVR.Overlay.GetPrimaryDashboardDevice(), ref cState, cStateSize); touch = new PointerTouchInfo(); touch.PointerInfo.pointerType = PointerInputType.TOUCH; touch.TouchFlags = TouchFlags.NONE; touch.Orientation = 0; touch.Pressure = 32000;//(uint)(cState.rAxis3.x * 2048); touch.PointerInfo.PointerFlags = PointerFlags.DOWN | PointerFlags.INRANGE | PointerFlags.INCONTACT; touch.TouchMasks = TouchMask.PRESSURE | TouchMask.CONTACTAREA; touch.PointerInfo.PtPixelLocation.X = _screenObject.Bounds.Left + (int)Math.Round((double)eventData.data.mouse.x); touch.PointerInfo.PtPixelLocation.Y = _screenObject.Bounds.Bottom - ((int)Math.Round((double)eventData.data.mouse.y) + touchYOffset); touch.ContactArea.top = touch.PointerInfo.PtPixelLocation.Y - 3; touch.ContactArea.bottom = touch.PointerInfo.PtPixelLocation.Y + 3; touch.ContactArea.left = touch.PointerInfo.PtPixelLocation.X - 6; touch.ContactArea.right = touch.PointerInfo.PtPixelLocation.X + 3; touch.PointerInfo.PointerId = 10; if (!TouchInjector.InjectTouchInput(1, new PointerTouchInfo[] { touch })) { Logger.Warning("[DESKTOP] Failed to inject touch down: " + GetLastError()); } else { isTouching = true; } }
private void UpdateTouches(uint touchIdFromLatestEvent) { lock (touchLock) { var arr = this.registeredTouches.Values.ToArray(); // For each registered touch, check whether we already injected the touch. // If not, we flag that the touch has been injected. // If yes, we make sure that the point flag is set to UPDATE instead of NEW // Why do we do this? We want to leverage the functionality provided by the Surface SDK 1.0 for // raising events on tap and hold. We don't want to inject any touch events when a user // touches the screen with one finger and triggers the ContactAdded-event. // However, we *do* need to remember that a touch event occurred, for the situation // that a user touches the screen with an additional finger. In that situation, when the // user would then initiate a pinch event, that event would fail if we don't remember // the first finger and inject that event anyway. // What happens if we don't use this approach? the user *can* pinch, but only if the first // finger moves around a little bit to trigger a ContactChange event, before touching the screen // with another finger, wait and then initiate the pinch movement. for (var i = 0; i < arr.Length; i++) { var id = arr[i].PointerInfo.PointerId; if (!this.injectedIds.Contains(id)) { this.injectedIds.Add(id); } else { arr[i].PointerInfo.PointerFlags = PointerFlags.UPDATE | PointerFlags.INRANGE | PointerFlags.INCONTACT; } if (id == touchIdFromLatestEvent) { continue; } } TouchInjector.InjectTouchInput(this.registeredTouches.Count, arr); } }
private void Start() { I = this; DPSettings.LoadConfigJson(); //StartCoroutine(DPSettings.AutoSave()); DPSettings.OnLoad(HandleMinimizeAtStartup); // TemplateWindowItem.selectedEvent += delegate(UwcWindow window) { NewDPWindowOverlay(window); }; WindowSelectListElement.onPressed += delegate(WindowSelectListElement element) { DPDesktopOverlay desktopDP; if (!element.isDesktop) { desktopDP = NewDPWindowOverlay(element.window); } else { desktopDP = NewDPMonitorOverlay(element.monitor); } TheBarManager.I.LaunchAppToMainSnap(desktopDP.dpAppParent.appKey); }; //SteamVRManager.I.onSteamVRConnected.AddListener(LoadDefaultLayout); //StartCoroutine(HandleOverlayRendering()); StartCoroutine(DPOverlayBase.HandleRendering()); TouchInjector.InitializeTouchInjection(); }
/// <summary> /// Finger down on the screen /// </summary> /// <param name="x">The X coordinate on the screen</param> /// <param name="y">The Y coordinate on the screen</param> /// <returns>true if successful, otherwise false</returns> public static bool TouchDown(int x, int y) { InitializeTouchInjection(); _contact = new PointerTouchInfo(); _contact.PointerInfo.pointerType = PointerInputType.TOUCH; _contact.PointerInfo.PointerId = 0; _contact.PointerInfo.PtPixelLocation.X = x; _contact.PointerInfo.PtPixelLocation.Y = y; _contact.TouchFlags = TouchFlags.NONE; _contact.TouchMasks = TouchMask.CONTACTAREA | TouchMask.ORIENTATION | TouchMask.PRESSURE; _contact.Orientation = 90; _contact.Pressure = 32000; _contact.ContactArea.top = _contact.PointerInfo.PtPixelLocation.Y - 2; _contact.ContactArea.bottom = _contact.PointerInfo.PtPixelLocation.Y + 2; _contact.ContactArea.left = _contact.PointerInfo.PtPixelLocation.X - 2; _contact.ContactArea.right = _contact.PointerInfo.PtPixelLocation.X + 2; _contact.PointerInfo.PointerFlags = PointerFlags.DOWN | PointerFlags.INRANGE | PointerFlags.INCONTACT; return(TouchInjector.InjectTouchInput(1, new [] { _contact })); }
public static void BeginDragging(Point point) { if (isDragging) { return; } activeContacts = new PointerTouchInfo[1]; activeContacts[0] = CreateDefaultPointerTouchInfo(point.X, point.Y, 2, 1); // Touch down activeContacts[0].PointerInfo.PointerFlags = PointerFlags.DOWN | PointerFlags.INRANGE | PointerFlags.INCONTACT; // Initial contact TouchInjector.InjectTouchInput(activeContacts.Length, activeContacts); previousPoint = point; isDragging = true; }
//FingerList public static void RunOne(FingerList Fingers) { List <Finger> sortedFingers = Fingers.OrderBy(Finger => Finger.TimeVisible).ToList(); sortedFingers.Reverse(); //List<Finger> sortedFingers = Fingers.ToList(); //temp int max = 1; float X, Y = 0; int speed = Properties.Settings.Default.TouchCursorSpeed; int numFingers = sortedFingers.Count; if (sortedFingers.Count >= max) { numFingers = max; } //numFingers - 1 for (int i = 0; i <= numFingers - 1; i++) { if (sortedFingers[i].TipPosition.z < Properties.Settings.Default.TouchThreshold) { isTouching[i] = true; } else { isTouching[i] = false; } if (isTouching[i] == true && Holding[i] == false) // pressed { JustPressed[i] = true; Holding[i] = true; } if (isTouching[i] == false && Holding[i] == true) // released { JustReleased[i] = true; Holding[i] = false; } if (JustPressed[i]) { JustPressed[i] = false; injector[i].PointerInfo.PointerFlags = PointerFlags.DOWN | PointerFlags.INRANGE | PointerFlags.INCONTACT; //MouseSimulator.ClickLeftMouseButton(); bool s0 = TouchInjector.InjectTouchInput(numFingers, injector); injector[i].PointerInfo.PointerFlags = PointerFlags.UPDATE | PointerFlags.INRANGE | PointerFlags.INCONTACT; } if (JustReleased[i]) { JustReleased[i] = false; injector[i].PointerInfo.PointerFlags = PointerFlags.UP | PointerFlags.INRANGE; bool s1 = TouchInjector.InjectTouchInput(numFingers, injector); } if (Holding[i] == false) { injector[i].PointerInfo.PointerFlags = PointerFlags.INRANGE | PointerFlags.UPDATE; //set to "hover mode" } X = sortedFingers[i].StabilizedTipPosition.x; Y = sortedFingers[i].StabilizedTipPosition.y; //X = sortedFingers[i].TipPosition.x; //Y = sortedFingers[i].TipPosition.y; //if (sortedFingers[i].TipVelocity.z > -20) injector[i].PointerInfo.PtPixelLocation.X = (int)(X * speed) + 1000; // 1000 injector[i].PointerInfo.PtPixelLocation.Y = -(int)(Y * speed) + 2700; // speed 15: add 2500 } bool s = TouchInjector.InjectTouchInput(numFingers, injector); SettingsWindow.debugText[1] = "Screen Coords:\n" + "X: " + injector[0].PointerInfo.PtPixelLocation.X + "Y: " + injector[0].PointerInfo.PtPixelLocation.Y; SettingsWindow.debugText[2] = "Z Velocity: " + sortedFingers[0].TipVelocity.z; SettingsWindow.debugText[4] = "Finger IDs: "; foreach (Finger f in sortedFingers) { SettingsWindow.debugText[4] += " " + f.Id; } }
public static void RunTwo(FingerList Fingers) { List <Finger> sortedFingers = Fingers.OrderBy(Finger => Finger.TimeVisible).ToList(); sortedFingers.Reverse(); //List<Finger> sortedFingers = Fingers.ToList(); //temp int max = 2; int numFingers = sortedFingers.Count; if (sortedFingers.Count >= max) { numFingers = max; } //numFingers - 1 for (int i = 0; i <= numFingers - 1; i++) { if (sortedFingers[i].TipPosition.z < Properties.Settings.Default.TouchThreshold) { isTouching[i] = true; } else { isTouching[i] = false; } if (isTouching[i] == true && Holding[i] == false) // pressed { JustPressed[i] = true; Holding[i] = true; } if (isTouching[i] == false && Holding[i] == true) // released { JustReleased[i] = true; Holding[i] = false; } if (JustPressed[i]) { JustPressed[i] = false; injector[i].PointerInfo.PointerFlags = PointerFlags.DOWN | PointerFlags.INRANGE | PointerFlags.INCONTACT; //MouseSimulator.ClickLeftMouseButton(); bool s0 = TouchInjector.InjectTouchInput(numFingers, injector); injector[i].PointerInfo.PointerFlags = PointerFlags.UPDATE | PointerFlags.INRANGE | PointerFlags.INCONTACT; } if (JustReleased[i]) { JustReleased[i] = false; injector[i].PointerInfo.PointerFlags = PointerFlags.UP | PointerFlags.INRANGE; bool s1 = TouchInjector.InjectTouchInput(numFingers, injector); } if (Holding[i] == false) { injector[i].PointerInfo.PointerFlags = PointerFlags.INRANGE | PointerFlags.UPDATE; //set to "hover mode" } //* Properties.Settings.Default.TouchCursorSpeed injector[i].PointerInfo.PtPixelLocation.X = (int)(sortedFingers[i].TipPosition.x * 10) + 1000; // 1000, 900 injector[i].PointerInfo.PtPixelLocation.Y = -(int)(sortedFingers[i].TipPosition.y * 10) + 1500; // speed 15: add 2500, 700 } //Fingers.Count bool s = TouchInjector.InjectTouchInput(numFingers, injector); //MouseSimulator.MoveCursor(injector[0].PointerInfo.PtPixelLocation.X, injector[0].PointerInfo.PtPixelLocation.Y); //MouseSimulator.MoveCursor(1920 / 2, 1180 / 2); //MouseSimulator.MoveCursor(MouseSimulator.mousePos.X + (int)(sortedFingers[0].TipVelocity.x * 0.5), MouseSimulator.mousePos.Y - (int)(sortedFingers[0].TipVelocity.y * 0.5)); SettingsWindow.debugText[4] = "Finger IDs: "; foreach (Finger f in sortedFingers) { SettingsWindow.debugText[4] += " " + f.Id; } //List<PointerTouchInfo> toInject = new List<PointerTouchInfo>(); //int numFingers = Fingers.Count; //if (Fingers.Count > 1) // numFingers = 1; ////Fingers.Count - 1 //for (int i = 0; i <= numFingers; i++) //{ // int ID = Fingers[i].Id; // int xPos = (int)(Fingers[i].TipPosition.x * multFactor) + 1000; // int yPos = -(int)(Fingers[i].TipPosition.y * multFactor) + 2500; // speed 15: add 2500 // PointerTouchInfo touchPoint = MakePointerTouchInfo(xPos, yPos, (uint)ID); // if (Fingers[i].TipPosition.z < touchThreshold) // isTouching[i] = true; // else // isTouching[i] = false; // if (isTouching[i] == true && Holding[i] == false) // pressed // { // JustPressed[i] = true; // Holding[i] = true; // } // if (isTouching[i] == false && Holding[i] == true) // released // { // JustReleased[i] = true; // Holding[i] = false; // } // if (JustPressed[i]) // { // JustPressed[i] = false; // touchPoint.PointerInfo.PointerFlags = PointerFlags.DOWN | PointerFlags.INRANGE | PointerFlags.INCONTACT; // } // else if (JustReleased[i]) // { // JustReleased[i] = false; // touchPoint.PointerInfo.PointerFlags = PointerFlags.UP | PointerFlags.INRANGE; // } // else if (Holding[i]) // touchPoint.PointerInfo.PointerFlags = PointerFlags.UPDATE | PointerFlags.INRANGE | PointerFlags.INCONTACT; // else // touchPoint.PointerInfo.PointerFlags = PointerFlags.INRANGE | PointerFlags.UPDATE; //set to "hover mode" // toInject.Add(touchPoint); //} //bool s = TouchInjector.InjectTouchInput(toInject.Count, toInject.ToArray()); }
public void Poll() { state = _controller.GetState(); gamepadState = state.Gamepad; if (gamepadState.GetHashCode() != old_state || stick2 || gamepadState.LeftTrigger > 0) { old_state = gamepadState.GetHashCode(); var leftStick = Normalize(gamepadState.LeftThumbX, gamepadState.LeftThumbY, Gamepad.LeftThumbDeadZone); var rightStick = Normalize(gamepadState.RightThumbX, gamepadState.RightThumbY, Gamepad.RightThumbDeadZone); // --------------------------------------------------------------------------------------------- // BUTTONS HANDLING // --------------------------------------------------------------------------------------------- if (gamepadState.LeftTrigger > 0) { if (!trigger1) { if (!moveattack) { ForceMove(false); } ForceStop(true); force_ratio_inc = 3; trigger1 = true; SendVibration(vb_stick); } } else { if (trigger1) { ForceStop(false); force_ratio_inc = 0; trigger1 = false; SendVibration(vb_null); } } // --------------------------------------------------------------------------------------------- // SKILL 1 // --------------------------------------------------------------------------------------------- if ((gamepadState.Buttons & _settings.GamepadButtonFlagsX) != 0) { if (!skill1) { _inputSimulator.Mouse.LeftButtonDown(); skill1 = true; } } else { if (skill1) { _inputSimulator.Mouse.LeftButtonUp(); skill1 = false; } } // --------------------------------------------------------------------------------------------- // SKILL 2 // --------------------------------------------------------------------------------------------- if ((gamepadState.Buttons & _settings.GamepadButtonFlagsA) != 0) { if (!skill2) { _inputSimulator.Mouse.RightButtonDown(); skill2 = true; } } else { if (skill2) { _inputSimulator.Mouse.RightButtonUp(); skill2 = false; } } // --------------------------------------------------------------------------------------------- // SKILL 3 // --------------------------------------------------------------------------------------------- if ((gamepadState.Buttons & _settings.GamepadButtonFlagsB) != 0) { if (!skill3) { _inputSimulator.Keyboard.KeyDown(VirtualKeyCode.VK_1); skill3 = true; } } else { if (skill3) { _inputSimulator.Keyboard.KeyUp(VirtualKeyCode.VK_1); skill3 = false; } } // --------------------------------------------------------------------------------------------- // SKILL 4 // --------------------------------------------------------------------------------------------- if ((gamepadState.Buttons & _settings.GamepadButtonFlagsY) != 0) { if (!skill4) { _inputSimulator.Keyboard.KeyDown(VirtualKeyCode.VK_2); skill4 = true; } } else { if (skill4) { _inputSimulator.Keyboard.KeyUp(VirtualKeyCode.VK_2); skill4 = false; } } // --------------------------------------------------------------------------------------------- // SKILL 5 // --------------------------------------------------------------------------------------------- if ((gamepadState.Buttons & _settings.GamepadButtonFlagsRightShoulder) != 0) { if (!skill5) { _inputSimulator.Keyboard.KeyDown(VirtualKeyCode.VK_3); skill5 = true; } } else { if (skill5) { _inputSimulator.Keyboard.KeyUp(VirtualKeyCode.VK_3); skill5 = false; } } // --------------------------------------------------------------------------------------------- // SKILL 6 // --------------------------------------------------------------------------------------------- if (gamepadState.RightTrigger > 0) { //MessageBox.Show("RightTrigger"); if (!skill6) { _inputSimulator.Keyboard.KeyDown(VirtualKeyCode.VK_4); skill6 = true; } } else { if (skill6) { _inputSimulator.Keyboard.KeyUp(VirtualKeyCode.VK_4); skill6 = false; } } // --------------------------------------------------------------------------------------------- // POTION // --------------------------------------------------------------------------------------------- if ((gamepadState.Buttons & _settings.GamepadButtonFlagsLeftShoulder) != 0) { if (!potion) { _inputSimulator.Keyboard.KeyDown(VirtualKeyCode.VK_Q); potion = true; } } else { if (potion) { _inputSimulator.Keyboard.KeyUp(VirtualKeyCode.VK_Q); potion = false; } } // --------------------------------------------------------------------------------------------- // START // --------------------------------------------------------------------------------------------- if ((gamepadState.Buttons & _settings.GamepadButtonFlagsStart) != 0) { if (!start) { _inputSimulator.Keyboard.KeyDown(VirtualKeyCode.ESCAPE); start = true; } } else { if (start) { _inputSimulator.Keyboard.KeyUp(VirtualKeyCode.ESCAPE); start = false; } } // --------------------------------------------------------------------------------------------- // CHARACTER // --------------------------------------------------------------------------------------------- if ((gamepadState.Buttons & _settings.GamepadButtonFlagsBack) != 0) { if (!character) { _inputSimulator.Keyboard.KeyDown(VirtualKeyCode.VK_I); character = true; } } else { if (character) { _inputSimulator.Keyboard.KeyUp(VirtualKeyCode.VK_I); character = false; } } // --------------------------------------------------------------------------------------------- // DPAD SETTINGS // --------------------------------------------------------------------------------------------- // --------------------------------------------------------------------------------------------- // SHOW ITEMS // --------------------------------------------------------------------------------------------- if ((gamepadState.Buttons & _settings.GamepadButtonFlagsDPadUp) != 0) { if (!show_item) { _inputSimulator.Keyboard.KeyDown(VirtualKeyCode.LMENU); show_item = true; } } else { if (show_item) { _inputSimulator.Keyboard.KeyUp(VirtualKeyCode.LMENU); show_item = false; } } // --------------------------------------------------------------------------------------------- // TOWN PORTAL // --------------------------------------------------------------------------------------------- if ((gamepadState.Buttons & _settings.GamepadButtonFlagsDPadRight) != 0) { if (!town_portal) { _inputSimulator.Keyboard.KeyDown(VirtualKeyCode.VK_T); town_portal = true; } } else { if (town_portal) { _inputSimulator.Keyboard.KeyUp(VirtualKeyCode.VK_T); town_portal = false; } } // --------------------------------------------------------------------------------------------- // SKILL // --------------------------------------------------------------------------------------------- if ((gamepadState.Buttons & _settings.GamepadButtonFlagsDPadLeft) != 0) { if (!skill) { _inputSimulator.Keyboard.KeyDown(VirtualKeyCode.VK_S); skill = true; } } else { if (skill) { _inputSimulator.Keyboard.KeyUp(VirtualKeyCode.VK_S); skill = false; } } // --------------------------------------------------------------------------------------------- // MAP // --------------------------------------------------------------------------------------------- if ((gamepadState.Buttons & _settings.GamepadButtonFlagsDPadDown) != 0) { if (!map) { _inputSimulator.Keyboard.KeyDown(VirtualKeyCode.TAB); map = true; } } else { if (map) { _inputSimulator.Keyboard.KeyUp(VirtualKeyCode.TAB); map = false; } } // --------------------------------------------------------------------------------------------- // SPACEBAR // --------------------------------------------------------------------------------------------- if ((gamepadState.Buttons & _settings.GamepadButtonFlagsLeftThumb) != 0) { if (!spacebar) { _inputSimulator.Keyboard.KeyDown(VirtualKeyCode.SPACE); spacebar = true; } } else { if (spacebar) { _inputSimulator.Keyboard.KeyUp(VirtualKeyCode.SPACE); spacebar = false; } } // --------------------------------------------------------------------------------------------- // CTRL // --------------------------------------------------------------------------------------------- if ((gamepadState.Buttons & _settings.GamepadButtonFlagsRightThumb) != 0) { if (!ctrl) { _inputSimulator.Keyboard.KeyDown(VirtualKeyCode.LCONTROL); ctrl = true; } } else { if (ctrl) { _inputSimulator.Keyboard.KeyUp(VirtualKeyCode.LCONTROL); ctrl = false; } } // --------------------------------------------------------------------------------------------- // JOYSTICKS HANDLING // --------------------------------------------------------------------------------------------- // --------------------------------------------------------------------------------------------- // AIM & ATTACK // --------------------------------------------------------------------------------------------- if (leftStick.X != 0 || leftStick.Y != 0 && !stick2) { if (!stick1) { stick1 = true; } cursor_x = 0; // Reset cursor for stick 2 cursor_y = 0; // Reset cursor for stick 2 var gamepad_x = Convert.ToInt16(leftStick.X * _settings.stick_speed); var gamepad_y = Convert.ToInt16(leftStick.Y * _settings.stick_speed); var x_ratio = gamepad_x * _settings.screenWidth_round / _settings.max; var y_ratio = gamepad_y * _settings.screenHeight / _settings.max; var returned_x = x_ratio / (_settings.force_ratio - force_ratio_inc); var returned_y = -y_ratio / (_settings.force_ratio - force_ratio_inc); x_value = _settings.c_screenWidth + returned_x; y_value = _settings.c_screenHeight + returned_y; if (!force_stop) { ForceMove(true); if (!touch) { contacts[0] = MakePointerTouchInfo(PointerInputType.TOUCH, PointerFlags.NONE, x_value, y_value, 1, 1, "Start"); touch = true; } else { contacts[0] = MakePointerTouchInfo(PointerInputType.TOUCH, PointerFlags.NONE, x_value, y_value, 1, 1, "Hover"); } TouchInjector.InjectTouchInput(1, contacts); } else { if (touch) { contacts[0] = MakePointerTouchInfo(PointerInputType.TOUCH, PointerFlags.NONE, x_value, y_value, 1, 1, "End"); TouchInjector.InjectTouchInput(1, contacts); touch = false; } MoveMouseTo(x_value, y_value); } } else { if (stick1) { if (touch) { contacts[0] = MakePointerTouchInfo(PointerInputType.TOUCH, PointerFlags.NONE, x_value, y_value, 1, 1, "End"); TouchInjector.InjectTouchInput(1, contacts); touch = false; } ForceMove(false); stick1 = false; } } // --------------------------------------------------------------------------------------------- // CURSOR // --------------------------------------------------------------------------------------------- if (rightStick.X != 0 || rightStick.Y != 0 && !stick1) { if (!stick2) { stick2 = true; } var gamepad_x2 = Convert.ToInt16(rightStick.X * _settings.stick_speed2); var gamepad_y2 = Convert.ToInt16(rightStick.Y * _settings.stick_speed2); var returned_x2 = gamepad_x2; var returned_y2 = -gamepad_y2; if (_settings.c_screenWidth + cursor_x + returned_x2 >= 0 && _settings.c_screenWidth + cursor_x + returned_x2 <= _settings.screenWidth) { cursor_x += returned_x2; } if (_settings.c_screenHeight + cursor_y + returned_y2 >= 0 && _settings.c_screenHeight + cursor_y + returned_y2 <= _settings.screenHeight) { cursor_y += returned_y2; } x_value = _settings.c_screenWidth + cursor_x; y_value = _settings.c_screenHeight + cursor_y; if (!stick1) { MoveMouseTo(x_value, y_value); } } else if (stick2) { stick2 = false; } } }
//public static void MoveContacts() //{ // //set x and y to new coords // for (int i = 0; i < numContacts(); i++) // { // injector[i].PointerInfo.PtPixelLocation.X = (int)lp.intersectPoint(i).X; // injector[i].PointerInfo.PtPixelLocation.Y = (int)lp.intersectPoint(i).Y; // } // bool s = TouchInjector.InjectTouchInput(numContacts(), injector); //} public static void Release(int index) { injector[index].PointerInfo.PointerFlags = PointerFlags.UP | PointerFlags.INRANGE; bool s1 = TouchInjector.InjectTouchInput(numActiveContacts(), injector); }
private async Task <bool> InitTouch() { await Task.Delay(0); return(TouchInjector.InitializeTouchInjection(maxTouchPoints, TouchFeedback.DEFAULT)); }
private void TuioChannel_OnTuioRefresh(TuioTime t) { //TODO: re-enable frequent screen monitoring //if (frameCount % checkScreenEvery == 0) // ScanScreens(); //loop through the TuioObjects List <PointerTouchInfo> toFire = new List <PointerTouchInfo>(); if (channel.CursorList.Count > 0) { foreach (var kvp in channel.CursorList) { TuioCursor cur = kvp.Value.TuioCursor; IncomingType type = kvp.Value.Type; int[] injectionCoordinates = ToInjectionCoordinates(cur.getX(), cur.getY()); //make a new pointertouchinfo with all neccessary information PointerTouchInfo contact = new PointerTouchInfo(); contact.PointerInfo.pointerType = PointerInputType.TOUCH; contact.TouchFlags = TouchFlags.NONE; //contact.Orientation = (uint)cur.getAngleDegrees();//this is only valid for TuioObjects contact.Pressure = pressure; contact.TouchMasks = TouchMask.CONTACTAREA | TouchMask.ORIENTATION | TouchMask.PRESSURE; contact.PointerInfo.PtPixelLocation.X = injectionCoordinates[0]; contact.PointerInfo.PtPixelLocation.Y = injectionCoordinates[1]; contact.PointerInfo.PointerId = SessionIDToTouchID(cur.getSessionID()); contact.ContactArea.left = injectionCoordinates[0] - areaRadius; contact.ContactArea.right = injectionCoordinates[0] + areaRadius; contact.ContactArea.top = injectionCoordinates[1] - areaRadius; contact.ContactArea.bottom = injectionCoordinates[1] + areaRadius; //set the right flag if (type == IncomingType.New) { contact.PointerInfo.PointerFlags = PointerFlags.DOWN | PointerFlags.INRANGE | PointerFlags.INCONTACT; } else if (type == IncomingType.Update) { contact.PointerInfo.PointerFlags = PointerFlags.UPDATE | PointerFlags.INRANGE | PointerFlags.INCONTACT; } else if (type == IncomingType.Remove) { contact.PointerInfo.PointerFlags = PointerFlags.UP; } //add it to 'toFire' toFire.Add(contact); } } //fire the events bool success = TouchInjector.InjectTouchInput(toFire.Count, toFire.ToArray()); //remove those with type == IncomingType.Remove List <long> removeList = new List <long>(); foreach (var kvp in channel.CursorList) { if (kvp.Value.Type == IncomingType.Remove) { removeList.Add(kvp.Key); } } foreach (long key in removeList) { channel.CursorList.Remove(key);//remove from the tuio channel } }
public static void Init() { TouchInjector.InitializeTouchInjection(); }
public void Poll() { state = _controller.GetState(); gamepadState = state.Gamepad; if (_settings.hasChanged) { cursor_x = _settings.d3_Rect.Left + _settings.c_d3Width; // Reset cursor for stick 2 cursor_y = _settings.d3_Rect.Top + _settings.c_d3Height; // Reset cursor for stick 2 } if (gamepadState.GetHashCode() != old_state || stick2 || gamepadState.LeftTrigger > 0) { old_state = gamepadState.GetHashCode(); var leftStick = Normalize(gamepadState.LeftThumbX, gamepadState.LeftThumbY, Gamepad.LeftThumbDeadZone); var rightStick = Normalize(gamepadState.RightThumbX, gamepadState.RightThumbY, Gamepad.RightThumbDeadZone); // --------------------------------------------------------------------------------------------- // BUTTONS HANDLING // --------------------------------------------------------------------------------------------- if (gamepadState.LeftTrigger > 0) { if (!trigger1) { if (!_settings.moveattack) { ForceMove(false); } ForceStop(true); force_ratio_inc = 2; trigger1 = true; Task.Factory.StartNew(() => SendVibration((int)rumble.weakest, 0, -1)); } } else { if (trigger1) { ForceStop(false); force_ratio_inc = 0; trigger1 = false; Task.Factory.StartNew(() => SendVibration(-1, 0, -1)); } } // --------------------------------------------------------------------------------------------- // SKILL 1 // --------------------------------------------------------------------------------------------- if ((gamepadState.Buttons & _settings.GamepadButtonFlagsX) != 0) { if (!skill1) { _inputSimulator.Mouse.LeftButtonDown(); skill1 = true; Task.Factory.StartNew(() => SendVibration(0, (int)rumble.weaker)); } } else { if (skill1) { _inputSimulator.Mouse.LeftButtonUp(); skill1 = false; } } // --------------------------------------------------------------------------------------------- // SKILL 2 // --------------------------------------------------------------------------------------------- if ((gamepadState.Buttons & _settings.GamepadButtonFlagsA) != 0) { if (!skill2) { _inputSimulator.Mouse.RightButtonDown(); skill2 = true; Task.Factory.StartNew(() => SendVibration(0, (int)rumble.weaker)); } } else { if (skill2) { _inputSimulator.Mouse.RightButtonUp(); skill2 = false; } } // --------------------------------------------------------------------------------------------- // SKILL 3 // --------------------------------------------------------------------------------------------- if ((gamepadState.Buttons & _settings.GamepadButtonFlagsB) != 0) { if (!skill3) { _inputSimulator.Keyboard.KeyDown(VKC_Skill3); skill3 = true; Task.Factory.StartNew(() => SendVibration(0, (int)rumble.weaker)); } } else { if (skill3) { _inputSimulator.Keyboard.KeyUp(VKC_Skill3); skill3 = false; } } // --------------------------------------------------------------------------------------------- // SKILL 4 // --------------------------------------------------------------------------------------------- if ((gamepadState.Buttons & _settings.GamepadButtonFlagsY) != 0) { if (!skill4) { _inputSimulator.Keyboard.KeyDown(VKC_Skill4); skill4 = true; Task.Factory.StartNew(() => SendVibration(0, (int)rumble.weaker)); } } else { if (skill4) { _inputSimulator.Keyboard.KeyUp(VKC_Skill4); skill4 = false; } } // --------------------------------------------------------------------------------------------- // SKILL 5 // --------------------------------------------------------------------------------------------- if ((gamepadState.Buttons & _settings.GamepadButtonFlagsRightShoulder) != 0) { if (!skill5) { _inputSimulator.Keyboard.KeyDown(VKC_Skill5); skill5 = true; Task.Factory.StartNew(() => SendVibration(0, (int)rumble.weaker)); } } else { if (skill5) { _inputSimulator.Keyboard.KeyUp(VKC_Skill5); skill5 = false; } } // --------------------------------------------------------------------------------------------- // SKILL 6 // --------------------------------------------------------------------------------------------- if (gamepadState.RightTrigger > 0) { if (!skill6) { _inputSimulator.Keyboard.KeyDown(VKC_Skill6); skill6 = true; Task.Factory.StartNew(() => SendVibration(0, (int)rumble.weaker)); } } else { if (skill6) { _inputSimulator.Keyboard.KeyUp(VKC_Skill6); skill6 = false; } } // --------------------------------------------------------------------------------------------- // POTION // --------------------------------------------------------------------------------------------- if ((gamepadState.Buttons & _settings.GamepadButtonFlagsLeftShoulder) != 0) { if (!potion) { _inputSimulator.Keyboard.KeyDown(VKC_Potion); potion = true; Task.Factory.StartNew(() => SendVibration(0, (int)rumble.weaker)); } } else { if (potion) { _inputSimulator.Keyboard.KeyUp(VKC_Potion); potion = false; } } // --------------------------------------------------------------------------------------------- // START // --------------------------------------------------------------------------------------------- if ((gamepadState.Buttons & _settings.GamepadButtonFlagsStart) != 0) { if (!start) { _inputSimulator.Keyboard.KeyDown(VKC_Start); start = true; Task.Factory.StartNew(() => SendVibration(0, (int)rumble.weaker)); } } else { if (start) { _inputSimulator.Keyboard.KeyUp(VKC_Start); start = false; } } // --------------------------------------------------------------------------------------------- // CHARACTER // --------------------------------------------------------------------------------------------- if ((gamepadState.Buttons & _settings.GamepadButtonFlagsBack) != 0) { if (!character) { _inputSimulator.Keyboard.KeyDown(VKC_Character); character = true; Task.Factory.StartNew(() => SendVibration(0, (int)rumble.weaker)); } } else { if (character) { _inputSimulator.Keyboard.KeyUp(VKC_Character); character = false; } } // --------------------------------------------------------------------------------------------- // DPAD SETTINGS // --------------------------------------------------------------------------------------------- // --------------------------------------------------------------------------------------------- // SHOW ITEMS // --------------------------------------------------------------------------------------------- if ((gamepadState.Buttons & _settings.GamepadButtonFlagsDPadUp) != 0) { if (!show_item) { _inputSimulator.Keyboard.KeyDown(VKC_Inventory); show_item = true; Task.Factory.StartNew(() => SendVibration(0, (int)rumble.weaker)); } } else { if (show_item) { _inputSimulator.Keyboard.KeyUp(VKC_Inventory); show_item = false; } } // --------------------------------------------------------------------------------------------- // TOWN PORTAL // --------------------------------------------------------------------------------------------- if ((gamepadState.Buttons & _settings.GamepadButtonFlagsDPadRight) != 0) { if (!town_portal) { _inputSimulator.Keyboard.KeyDown(VKC_TownPortal); town_portal = true; Task.Factory.StartNew(() => SendVibration(0, (int)rumble.weaker)); } } else { if (town_portal) { _inputSimulator.Keyboard.KeyUp(VKC_TownPortal); town_portal = false; } } // --------------------------------------------------------------------------------------------- // SKILL // --------------------------------------------------------------------------------------------- if ((gamepadState.Buttons & _settings.GamepadButtonFlagsDPadLeft) != 0) { if (!skill) { _inputSimulator.Keyboard.KeyDown(VKC_Skill); skill = true; Task.Factory.StartNew(() => SendVibration(0, (int)rumble.weaker)); } } else { if (skill) { _inputSimulator.Keyboard.KeyUp(VKC_Skill); skill = false; } } // --------------------------------------------------------------------------------------------- // MAP // --------------------------------------------------------------------------------------------- if ((gamepadState.Buttons & _settings.GamepadButtonFlagsDPadDown) != 0) { if (!map) { _inputSimulator.Keyboard.KeyDown(VKC_MAP); map = true; Task.Factory.StartNew(() => SendVibration(0, (int)rumble.weaker)); } } else { if (map) { _inputSimulator.Keyboard.KeyUp(VKC_MAP); map = false; } } // --------------------------------------------------------------------------------------------- // SPACEBAR // --------------------------------------------------------------------------------------------- if ((gamepadState.Buttons & _settings.GamepadButtonFlagsLeftThumb) != 0) { if (!spacebar) { _inputSimulator.Keyboard.KeyDown(VKC_SKIP); spacebar = true; Task.Factory.StartNew(() => SendVibration(0, (int)rumble.weaker)); } } else { if (spacebar) { _inputSimulator.Keyboard.KeyUp(VKC_SKIP); spacebar = false; } } // --------------------------------------------------------------------------------------------- // CTRL // --------------------------------------------------------------------------------------------- if ((gamepadState.Buttons & _settings.GamepadButtonFlagsRightThumb) != 0) { if (!ctrl) { _inputSimulator.Keyboard.KeyDown(VKC_HINTS); ctrl = true; Task.Factory.StartNew(() => SendVibration(0, (int)rumble.weaker)); } } else { if (ctrl) { _inputSimulator.Keyboard.KeyUp(VKC_HINTS); ctrl = false; } } // --------------------------------------------------------------------------------------------- // JOYSTICKS HANDLING // --------------------------------------------------------------------------------------------- // --------------------------------------------------------------------------------------------- // AIM & ATTACK : Fixed // --------------------------------------------------------------------------------------------- if (leftStick.X != 0 || leftStick.Y != 0 && !stick2) { if (!stick1) { stick1 = true; } cursor_x = _settings.d3_Rect.Left + _settings.c_d3Width; // Reset cursor for stick 2 cursor_y = _settings.d3_Rect.Top + _settings.c_d3Height; // Reset cursor for stick 2 float gamepad_x = Convert.ToInt32(leftStick.X * (float)_settings.stick_speed); float gamepad_y = Convert.ToInt32(leftStick.Y * (float)_settings.stick_speed); float x_ratio = gamepad_x * (float)_settings.d3Height / (float)_settings.max; float y_ratio = gamepad_y * (float)_settings.d3Height / (float)_settings.max; float returned_x = x_ratio / ((float)_settings.force_ratio - (float)force_ratio_inc); float returned_y = -y_ratio / ((float)_settings.force_ratio - (float)force_ratio_inc); x_value = _settings.c_d3Width + _settings.d3_Rect.Left + returned_x; y_value = _settings.c_d3Height + _settings.d3_Rect.Top + returned_y; if (!force_stop) { ForceMove(true); if (!touch) { contacts[0] = MakePointerTouchInfo(PointerInputType.TOUCH, PointerFlags.NONE, (int)x_value, (int)y_value, 1, 1, "Start"); touch = true; } else { contacts[0] = MakePointerTouchInfo(PointerInputType.TOUCH, PointerFlags.NONE, (int)x_value, (int)y_value, 1, 1, "Hover"); } TouchInjector.InjectTouchInput(1, contacts); } else { if (touch) { contacts[0] = MakePointerTouchInfo(PointerInputType.TOUCH, PointerFlags.NONE, (int)x_value, (int)y_value, 1, 1, "End"); TouchInjector.InjectTouchInput(1, contacts); touch = false; } MoveMouseTo(x_value, y_value); } } else { if (stick1) { if (touch) { contacts[0] = MakePointerTouchInfo(PointerInputType.TOUCH, PointerFlags.NONE, (int)x_value, (int)y_value, 1, 1, "End"); TouchInjector.InjectTouchInput(1, contacts); touch = false; } ForceMove(false); stick1 = false; } } // --------------------------------------------------------------------------------------------- // CURSOR // --------------------------------------------------------------------------------------------- if (rightStick.X != 0 || rightStick.Y != 0 && !stick1) { if (!stick2) { stick2 = true; } var gamepad_x2 = Convert.ToInt16(rightStick.X * _settings.stick_speed2); var gamepad_y2 = Convert.ToInt16(rightStick.Y * _settings.stick_speed2); var returned_x2 = gamepad_x2; var returned_y2 = -gamepad_y2; if (cursor_x + returned_x2 < _settings.d3_Rect.Left + _settings.d3Width) { if (cursor_x + returned_x2 > _settings.d3_Rect.Left) { cursor_x += returned_x2; } } if (cursor_y + returned_y2 > _settings.d3_Rect.Top) { if (cursor_y + returned_y2 < _settings.d3_Rect.Bottom) { cursor_y += returned_y2; } } if (!stick1) { MoveMouseTo(cursor_x, cursor_y); } } else if (stick2) { stick2 = false; } } }
public MainWindow() { this.Loaded += MainWindow_Loaded; InitializeComponent(); TouchInjector.InitializeTouchInjection(); mainCanvas.Width = Screen.PrimaryScreen.Bounds.Width; mainCanvas.Height = Screen.PrimaryScreen.Bounds.Height; BitmapImage bi0 = new BitmapImage(); bi0.BeginInit(); bi0.UriSource = new Uri(Globals.ExecutablePath + "\\win_cursor_plus\\cursor0.png"); bi0.EndInit(); BitmapImage bi1 = new BitmapImage(); bi1.BeginInit(); bi1.UriSource = new Uri(Globals.ExecutablePath + "\\win_cursor_plus\\cursor1.png"); bi1.EndInit(); cursorImageIndex.Source = bi0; cursorImageIndex.Width = cursorImageIndex.Height = 100; cursorImageThumb.Source = bi0; cursorImageThumb.Width = cursorImageThumb.Height = 100; cursorImageIndex.Opacity = 0; cursorImageThumb.Opacity = 0; IPC ipc = new IPC("win_cursor_plus"); ipc.MapFunction("exit", delegate(string messageBody) { ipc.Clear(); Environment.Exit(0); return(1); }); ipc.SetUDPCallback(delegate(string message) { if (message != "hide_cursor_index" || message != "hide_cursor_thumb") { string[] xyStr = message.Split('!'); if (xyStr.Length == 5) { cursorIndexDown = false; cursorThumbDown = false; float x; float y; float z; int down; bool b0 = float.TryParse(xyStr[0], System.Globalization.NumberStyles.Float, null, out x); bool b1 = float.TryParse(xyStr[1], System.Globalization.NumberStyles.Float, null, out y); bool b2 = float.TryParse(xyStr[2], System.Globalization.NumberStyles.Float, null, out z); bool b3 = int.TryParse(xyStr[3], System.Globalization.NumberStyles.Float, null, out down); if (b0 && b1 && b2) { if (xyStr[4] == "index") { xCursorIndex = x * screenWidth / 1000; if (xCursorIndex < 0) { xCursorIndex = 0; } else if (xCursorIndex > screenWidth) { xCursorIndex = screenWidth; } yCursorIndex = y * screenHeight / 1000; if (yCursorIndex < 0) { yCursorIndex = 0; } else if (yCursorIndex > screenHeight) { yCursorIndex = screenHeight; } zCursorIndex = z; showCursorIndex = true; cursorIndexDown = down == 1; } else if (xyStr[4] == "thumb") { xCursorThumb = x * screenWidth / 1000; if (xCursorThumb < 0) { xCursorThumb = 0; } else if (xCursorThumb > screenWidth) { xCursorThumb = screenWidth; } yCursorThumb = y * screenHeight / 1000; if (yCursorThumb < 0) { yCursorThumb = 0; } else if (yCursorThumb > screenHeight) { yCursorThumb = screenHeight; } zCursorThumb = z; showCursorThumb = true; cursorIndexDown = true; cursorThumbDown = true; } } } else if (message == "hide_cursor_index") { showCursorIndex = false; } else if (message == "hide_cursor_thumb") { showCursorThumb = false; } else if (xyStr.Length == 2 && xyStr[0] == "update") { updateNumNew = int.Parse(xyStr[1]); } } return(1); }); Timer ipcTimer = new Timer(); ipcTimer.Interval = 100; ipcTimer.Tick += delegate(object o, EventArgs e) { ipc.Update(); }; ipcTimer.Start(); Timer timer = new Timer(); timer.Interval = 20; timer.Tick += delegate(object o, EventArgs e) { if (updateNumNew == updateNumOld && showCursorIndex) { return; } updateNumOld = updateNumNew; if (!useTUIO && showCursorIndex) { if (!useFallback) { List <PointerTouchInfo> contacts = new List <PointerTouchInfo>(); if (cursorIndexDown && !cursorIndexDownOld) { PointerTouchInfo contact = MakePointerTouchInfo((int)xCursorIndex, (int)yCursorIndex, 2, 1); contact.PointerInfo.PointerFlags = PointerFlags.DOWN | PointerFlags.INRANGE | PointerFlags.INCONTACT; contacts.Add(contact); } else if (cursorIndexDown && cursorIndexDownOld) { PointerTouchInfo contact = MakePointerTouchInfo((int)xCursorIndex, (int)yCursorIndex, 2, 1); contact.PointerInfo.PointerFlags = PointerFlags.UPDATE | PointerFlags.INRANGE | PointerFlags.INCONTACT; contacts.Add(contact); } else if (!cursorIndexDown && cursorIndexDownOld) { PointerTouchInfo contact = MakePointerTouchInfo((int)xCursorIndexOld, (int)yCursorIndexOld, 2, 1); contact.PointerInfo.PointerFlags = PointerFlags.UP; contacts.Add(contact); } if (cursorThumbDown && !cursorThumbDownOld) { PointerTouchInfo contact = MakePointerTouchInfo((int)xCursorThumb, (int)yCursorThumb, 2, 2); contact.PointerInfo.PointerFlags = PointerFlags.DOWN | PointerFlags.INRANGE | PointerFlags.INCONTACT; contacts.Add(contact); } else if (cursorThumbDown && cursorThumbDownOld) { PointerTouchInfo contact = MakePointerTouchInfo((int)xCursorThumb, (int)yCursorThumb, 2, 2); contact.PointerInfo.PointerFlags = PointerFlags.UPDATE | PointerFlags.INRANGE | PointerFlags.INCONTACT; contacts.Add(contact); } else if (!cursorThumbDown && cursorThumbDownOld) { PointerTouchInfo contact = MakePointerTouchInfo((int)xCursorThumbOld, (int)yCursorThumbOld, 2, 2); contact.PointerInfo.PointerFlags = PointerFlags.UP; contacts.Add(contact); } bool success = TouchInjector.InjectTouchInput(contacts.Count, contacts.ToArray()); } else { System.Windows.Forms.Cursor.Position = new System.Drawing.Point((int)xCursorIndex, (int)yCursorIndex); if (cursorIndexDown) { mouseDown(); } else { mouseUp(); } } } else if (showCursorIndex) { Object[] tCur0 = new Object[7]; Object[] tCur1 = new Object[7]; OSCBundle bundle = new OSCBundle(); bundle.Append(TUIO.TUIOFseq(tuioFSeq)); ArrayList TUIOSessions = new ArrayList(); if (cursorIndexDown) { bundle.Append(TUIO.TUIO2DcurExt(0, xCursorIndex / screenWidth, yCursorIndex / screenHeight, 0, 0, 0, 10, 10)); TUIOSessions.Add(0); } if (cursorThumbDown) { bundle.Append(TUIO.TUIO2DcurExt(1, xCursorThumb / screenWidth, yCursorThumb / screenHeight, 0, 0, 0, 10, 10)); TUIOSessions.Add(1); } bundle.Append(TUIO.TUIOAlive(TUIOSessions)); transmitter.Send(bundle); tuioFSeq++; } if (showCursorIndex) { if (cursorIndexDown) { cursorImageIndex.Source = bi1; } else { cursorImageIndex.Source = bi0; } if (cursorImageIndex.Opacity < 1) { cursorImageIndex.Opacity += 0.2; } int cursorSize = (int)(zCursorIndex * 5 * (float)windowWidth / (float)screenWidth); if (cursorSize > 150) { cursorSize = 150; } else if (cursorSize < 50) { cursorSize = 50; } cursorImageIndex.Width = cursorImageIndex.Height = cursorSize; int xPosRemapped = (int)map_val(xCursorIndex, 0, screenWidth, 0, windowWidth); int yPosRemapped = (int)map_val(yCursorIndex, 0, screenHeight, 0, windowHeight); if (xPosRemapped < 0) { xPosRemapped = 0; } else if (xPosRemapped > screenWidth) { xPosRemapped = screenWidth; } if (yPosRemapped < 0) { yPosRemapped = 0; } else if (yPosRemapped > screenHeight) { yPosRemapped = screenHeight; } Canvas.SetLeft(cursorImageIndex, xPosRemapped - (cursorSize / 2)); Canvas.SetTop(cursorImageIndex, yPosRemapped - (cursorSize / 2)); } else if (cursorImageIndex.Opacity > 0) { cursorImageIndex.Opacity -= 0.2; } if (showCursorThumb) { if (cursorThumbDown) { cursorImageThumb.Source = bi1; } else { cursorImageThumb.Source = bi0; } if (cursorImageThumb.Opacity < 1) { cursorImageThumb.Opacity += 0.2; } int cursorSize = (int)(zCursorThumb * 5 * (float)windowWidth / (float)screenWidth); if (cursorSize > 150) { cursorSize = 150; } else if (cursorSize < 50) { cursorSize = 50; } cursorImageThumb.Width = cursorImageThumb.Height = cursorSize; int xPosRemapped = (int)map_val(xCursorThumb, 0, screenWidth, 0, windowWidth); int yPosRemapped = (int)map_val(yCursorThumb, 0, screenHeight, 0, windowHeight); if (xPosRemapped < 0) { xPosRemapped = 0; } else if (xPosRemapped > screenWidth) { xPosRemapped = screenWidth; } if (yPosRemapped < 0) { yPosRemapped = 0; } else if (yPosRemapped > screenHeight) { yPosRemapped = screenHeight; } Canvas.SetLeft(cursorImageThumb, xPosRemapped - (cursorSize / 2)); Canvas.SetTop(cursorImageThumb, yPosRemapped - (cursorSize / 2)); } else if (cursorImageThumb.Opacity > 0) { cursorImageThumb.Opacity -= 0.2; } cursorIndexDownOld = cursorIndexDown; cursorThumbDownOld = cursorThumbDown; xCursorThumbOld = xCursorThumb; yCursorThumbOld = yCursorThumb; zCursorThumbOld = zCursorThumb; xCursorIndexOld = xCursorIndex; yCursorIndexOld = yCursorIndex; zCursorIndexOld = zCursorIndex; }; timer.Start(); }
public void Install() { var thread = new Thread(() => { _win = new InputTargetWindow(); var ok = RegisterPointerInputTarget(_win.Handle, PointerInputType.TOUCH); if (!ok) { Debug.WriteLine("失败 RegisterPointerInputTarget: " + Native.GetLastError()); return; //todo: !! } else { Debug.WriteLine("TouchHook Installed."); } Native.MSG msg; int ret; var sim = new InputSimulator(); TouchInjector.InitializeTouchInjection(); var screenBounds = Rectangle.Empty; var contacts = new PointerTouchInfo[10]; uint contactCount = 10; uint startingPointId = 0; while ((ret = Native.GetMessage(out msg, IntPtr.Zero, 0, 0)) != 0) { if (ret == -1) { Debug.WriteLine("Error!"); continue; } var pointerId = GET_POINTERID_WPARAM((uint)msg.wParam.ToInt32()); if (!GetPointerFrameTouchInfo(pointerId, ref contactCount, contacts)) { Debug.WriteLine("GetPointerFrameTouchInfo Error: " + Native.GetLastError()); continue; } //TODO: refactor... just hacking... switch (msg.message) { case WM_POINTERDOWN: Debug.WriteLine("Touch Down: " + contactCount); if (contactCount == 3) { startingPointId = contacts[0].PointerInfo.PointerId; if (screenBounds.Width > 0 && screenBounds.Height > 0) { var pos = contacts[0].PointerInfo.PtPixelLocation; User32.SetCursorPos(pos.X, pos.Y); } screenBounds = Native.GetScreenBounds(); sim.Keyboard.KeyDown(WindowsInput.Native.VirtualKeyCode.LWIN); continue; } ConvertToNewTouchInfo(contacts, PointerFlags.DOWN | PointerFlags.INRANGE | PointerFlags.INCONTACT); if (!TouchInjector.InjectTouchInput(1, contacts)) { Debug.WriteLine("Error InjectTouchInput: " + Native.GetLastError()); } break; case WM_POINTERUPDATE: Debug.Write('.'); if (contactCount == 3) { TouchPoint?pos = null; foreach (var contact in contacts) { if (contact.PointerInfo.PointerId == startingPointId) { pos = contact.PointerInfo.PtPixelLocation; } } if (pos != null && screenBounds.Width > 0 && screenBounds.Height > 0) { var absX = pos.Value.X * (65535.0 / screenBounds.Width); var absY = pos.Value.Y * (65535.0 / screenBounds.Height); sim.Mouse.MoveMouseTo(absX, absY); } continue; } ConvertToNewTouchInfo(contacts, PointerFlags.UPDATE | PointerFlags.INRANGE | PointerFlags.INCONTACT); if (!TouchInjector.InjectTouchInput((int)contactCount, contacts)) { Debug.WriteLine("Error InjectTouchInput: " + Native.GetLastError()); } break; case WM_POINTERUP: Debug.WriteLine("Touch Up"); if (contactCount == 3) { sim.Keyboard.KeyUp(WindowsInput.Native.VirtualKeyCode.LWIN); continue; } ConvertToNewTouchInfo(contacts, PointerFlags.UP); if (!TouchInjector.InjectTouchInput(1, contacts)) { Debug.WriteLine("Error InjectTouchInput: " + Native.GetLastError()); } break; case WM_POINTERENTER: Debug.WriteLine("Touch Enter"); //ConvertToNewTouchInfo(contacts, PointerFlags.DOWN | PointerFlags.INRANGE | PointerFlags.INCONTACT); continue; case WM_POINTERLEAVE: Debug.WriteLine("Touch Leave"); //ConvertToNewTouchInfo(contacts, PointerFlags.UP | PointerFlags.INRANGE | PointerFlags.INCONTACT); continue; default: Debug.WriteLine("Unhandled Msg: " + msg.message); continue; } var MSG = new Message() { HWnd = msg.hwnd, LParam = msg.lParam, WParam = msg.wParam, Msg = (int)msg.message, Result = IntPtr.Zero }; _win.DefWndProc(ref MSG); } }); thread.Start(); }
public static void Run() { for (int i = 0; i < numControllers; i++) { SetActiveContact(contacts[i], i); //determine whether the contact is active (undocked) } for (int i = 0; i < numControllers; i++) { int index = (numActiveContacts() - 1) * i; //int index = contacts[i].ID; //int index = (int)injector[i].PointerInfo.PointerId; //int index = contacts[i].ControllerIndex; if (contacts[i].Active) { if (ControllerData.controller[i].one == true && contacts[i].Holding == false) // pressed { contacts[i].JustPressed = true; contacts[i].Holding = true; } if (ControllerData.controller[i].one == false && contacts[i].Holding == true) // released { contacts[i].JustReleased = true; contacts[i].Holding = false; } if (contacts[i].JustPressed) { contacts[i].JustPressed = false; TouchActions.TouchDown(index); } if (contacts[i].JustReleased) { contacts[i].JustReleased = false; TouchActions.Release(index); } if (contacts[i].Holding == false) { TouchActions.SetHover(index); } if (ControllerData.controller[i].start == true) { LaserPointer.Calibrate(index); } injector[index].PointerInfo.PtPixelLocation.X = (int)lp.intersectPoint(i).X; injector[index].PointerInfo.PtPixelLocation.Y = (int)lp.intersectPoint(i).Y; } } bool s = TouchInjector.InjectTouchInput(numActiveContacts(), injector); //for (int i = 0; i < numControllers; i++) //{ // int index = (numActiveContacts() - 1) * i; // //int index = contacts[i].ID; // //int index = (int)injector[i].PointerInfo.PointerId; // if (contacts[i].Active) // { // if (ControllerData.controller[i].one == true && contacts[i].Holding == false) // pressed // { // contacts[i].JustPressed = true; // contacts[i].Holding = true; // } // if (ControllerData.controller[i].one == false && contacts[i].Holding == true) // released // { // contacts[i].JustReleased = true; // contacts[i].Holding = false; // } // if (contacts[i].JustPressed) // { // contacts[i].JustPressed = false; // TouchActions.TouchDown(index); // } // if (contacts[i].JustReleased) // { // contacts[i].JustReleased = false; // TouchActions.Release(index); // } // if (contacts[i].Holding == false) // TouchActions.SetHover(index); // if (ControllerData.controller[i].start == true) // LaserPointer.Calibrate(index); // injector[index].PointerInfo.PtPixelLocation.X = (int)lp.intersectPoint(i).X; // injector[index].PointerInfo.PtPixelLocation.Y = (int)lp.intersectPoint(i).Y; // } //} SettingsWindow.debugText[2] = "\nnumActiveContacts: " + numActiveContacts() + "\nc0 active: " + contacts[0].Active + "\nc1 active: " + contacts[1].Active + "\nc0 ID: " + contacts[0].ID + "\nc1 ID: " + contacts[1].ID + "\ninjectorlist count: " + injectorList.Count(); //"\ninjectorArray leng: " + injector.Count(); }
public static void Run(FingerList Fingers) { List <Finger> sortedFingers = Fingers.OrderBy(Finger => Finger.TimeVisible).ToList(); sortedFingers.Reverse(); List <TouchContact> updatedContacts = new List <TouchContact>(); List <PointerTouchInfo> toInject = new List <PointerTouchInfo>(); for (int i = 0; i <= sortedFingers.Count - 1; i++) { int ID = sortedFingers[i].Id; int xPos = (int)(sortedFingers[i].TipPosition.x * Properties.Settings.Default.TouchCursorSpeed) + 1000; //1000 int yPos = -(int)(sortedFingers[i].TipPosition.y * Properties.Settings.Default.TouchCursorSpeed) + 3300; // speed 15: add 2500 float zPos = sortedFingers[i].TipPosition.z; updatedContacts.Add(new TouchContact(xPos, yPos, zPos, ID)); int foundIndex = contacts.FindIndex(TouchContact => TouchContact.ID == updatedContacts[i].ID); if (foundIndex >= 0) //a matching ID was found { //transfer the data to the updated contacts updatedContacts[i].Holding = contacts[foundIndex].Holding; updatedContacts[i].JustPressed = contacts[foundIndex].JustPressed; updatedContacts[i].JustReleased = contacts[foundIndex].JustReleased; } } // sort the contacts by ID so they keep consistent indexes over time //contacts = updatedContacts.OrderBy(TouchContact => TouchContact.ID).ToList(); contacts = updatedContacts; for (int i = 0; i <= sortedFingers.Count - 1; i++) { PointerTouchInfo touchPoint = MakePointerTouchInfo(contacts[i].PosX, contacts[i].PosY, (uint)contacts[i].ID); if (i <= injector.Length - 1) { //injector[i].PointerInfo.PointerId = (uint)contacts[i].ID; if (contacts[i].PosZ < Properties.Settings.Default.TouchThreshold && contacts[i].Holding == false) // pressed { contacts[i].JustPressed = true; contacts[i].Holding = true; } if (contacts[i].PosZ > Properties.Settings.Default.TouchThreshold && contacts[i].Holding == true) // released { contacts[i].JustReleased = true; contacts[i].Holding = false; } if (contacts[i].JustPressed) { contacts[i].JustPressed = false; touchPoint.PointerInfo.PointerFlags = PointerFlags.DOWN | PointerFlags.INRANGE | PointerFlags.INCONTACT; } else if (contacts[i].JustReleased) { contacts[i].JustReleased = false; touchPoint.PointerInfo.PointerFlags = PointerFlags.UP | PointerFlags.INRANGE; } else if (contacts[i].Holding) { touchPoint.PointerInfo.PointerFlags = PointerFlags.UPDATE | PointerFlags.INRANGE | PointerFlags.INCONTACT; } else { touchPoint.PointerInfo.PointerFlags = PointerFlags.INRANGE | PointerFlags.UPDATE; //set to "hover mode" } toInject.Add(touchPoint); } } //injector.Length bool s = TouchInjector.InjectTouchInput(toInject.Count, toInject.ToArray()); SettingsWindow.debugText[2] = "contacts: "; foreach (TouchContact c in contacts) { SettingsWindow.debugText[2] += " " + c.ID; // + " " + c.Holding } //List<TouchContact> newContacts = new List<TouchContact>(); ////List<PointerTouchInfo> toFire = new List<PointerTouchInfo>(); //foreach (Finger finger in Fingers) //{ // int xPos = (int)(finger.TipPosition.x * multFactor) + 1000; // speed 15: 1000 // int yPos = -(int)(finger.TipPosition.y * multFactor) + 2500; // speed 15: add 2500 // float zPos = finger.TipPosition.z; // //injectorList.Add(MakePointerTouchInfo(xPos, yPos, (uint)finger.Id)); // newContacts.Add(new TouchContact(xPos, yPos, zPos, finger.Id)); //} ////injector = injectorList.ToArray(); ////injectorList.Clear(); //List<TouchContact> updatedContacts = new List<TouchContact>(); //int foundIndex; ////todo: combine with foreach finger loop ////newContacts.Count - 1 //for (int i = 0; i <= newContacts.Count - 1; i++) //{ // updatedContacts.Add(newContacts[i]); // foundIndex = contacts.FindIndex(TouchContact => TouchContact.ID == updatedContacts[i].ID); // if (foundIndex >= 0) //a matching ID was found // { // //transfer the data to the updated contacts // updatedContacts[i].Holding = contacts[foundIndex].Holding; // updatedContacts[i].JustPressed = contacts[foundIndex].JustPressed; // updatedContacts[i].JustReleased = contacts[foundIndex].JustReleased; // } //} //contacts = updatedContacts; ////contacts.Count - 1 //for (int i = 0; i <= Fingers.Count - 1; i++) //{ // if (i <= injector.Length - 1) // { // //injector[i].PointerInfo.PointerId = (uint)contacts[i].ID; // if (contacts[i].PosZ < touchThreshold && contacts[i].Holding == false) // pressed // { // contacts[i].JustPressed = true; // contacts[i].Holding = true; // } // if (contacts[i].PosZ > touchThreshold && contacts[i].Holding == true) // released // { // contacts[i].JustReleased = true; // contacts[i].Holding = false; // } // if (contacts[i].JustPressed) // { // contacts[i].JustPressed = false; // injector[i].PointerInfo.PointerFlags = PointerFlags.DOWN | PointerFlags.INRANGE | PointerFlags.INCONTACT; // } // else if (contacts[i].JustReleased) // { // contacts[i].JustReleased = false; // injector[i].PointerInfo.PointerFlags = PointerFlags.UP | PointerFlags.INRANGE; // } // else if (contacts[i].Holding) // { // injector[i].PointerInfo.PointerFlags = PointerFlags.UPDATE | PointerFlags.INRANGE | PointerFlags.INCONTACT; // } // else // { // injector[i].PointerInfo.PointerFlags = PointerFlags.INRANGE | PointerFlags.UPDATE; //set to "hover mode" // } // injector[i].PointerInfo.PtPixelLocation.X = (int)(Fingers[i].TipPosition.x * multFactor) + 800; // speed 15: 1000 // injector[i].PointerInfo.PtPixelLocation.Y = -(int)(Fingers[i].TipPosition.y * multFactor) + 1800; // speed 15: add 2500 // } //} ////Form1.debugText[3] = "Fingers: "; ////foreach (Finger f in Fingers) //// Form1.debugText[3] += " " + f.Id; ////if (released) //// Form1.debugText[3] += "r"; ////released = false; ////injector.Length //bool s = TouchInjector.InjectTouchInput(Fingers.Count, injector); ////Form1.debugText[1] = "Injector length: " + injector.Length + " contacts count: " + contacts.Count; //Form1.debugText[2] = "contacts: "; //foreach (TouchContact c in contacts) // Form1.debugText[2] += " " + c.ID + " " + c.Holding; ////Form1.debugText[3] = ""; ////Form1.debugText[4] = "" + s; }
public MainWindow() { InitializeComponent(); IsAlive = true; // TOUCH SETTINGS TouchInjector.InitializeTouchInjection(); _inputSimulator = new InputSimulator(); // CONTROLLER SETTINGS _settings = new ControllerSettings(); _gameController = new GameController(new Controller(UserIndex.One), _settings, _inputSimulator); // STATICS myForm = Form1; myCanvas = Canvas1; myGamepad = GamepadIco; string ico = "Menu"; for (int i = 0; i < 7; i++) { switch (i) { case 0: ico = "B"; break; case 1: ico = "Y"; break; case 2: ico = "RB"; break; case 3: ico = "RT"; break; case 4: ico = "X"; break; case 5: ico = "A"; break; case 6: ico = "LB"; break; } System.Windows.Shapes.Rectangle rect = new System.Windows.Shapes.Rectangle { Fill = new ImageBrush { ImageSource = ImageSourceFromBitmap(GetImageByName("XBOne_" + ico)) }, Stretch = Stretch.Uniform, }; myCanvas.Children.Add(rect); } Thread myThread = new Thread(new ThreadStart(ThreadHealth)); myThread.Start(); Thread myThread2 = new Thread(new ThreadStart(ThreadGamepad)); myThread2.Start(); Thread myThread3 = new Thread(new ThreadStart(ThreadUI)); myThread3.Start(); }
public static void Release(int index, int numFingers) { injector[index].PointerInfo.PointerFlags = PointerFlags.UP | PointerFlags.INRANGE; //injector.Length, 1 bool s1 = TouchInjector.InjectTouchInput(numFingers, injector); }
public static void TouchDown(Point pointOnScreen) { var contact = MakePointerTouchInfo((int)pointOnScreen.X, (int)pointOnScreen.Y, 2, 1); TouchInjector.InjectTouchInput(1, new[] { contact }); }