private void MouseUp(Window32Msg.MouseOrigin origin, MouseButton arg1, MousePoint arg2) { MouseInputData data = new MouseInputData(); data.Get((int)arg1).Up = true; OriginType type = OriginType.U3D_2D_MOUSE; switch (origin) { case Window32Msg.MouseOrigin.PRO_MOUSE: type = PROIs3DShow ? OriginType.PRO_3D_MOUSE : OriginType.PRO_2D_MOUSE; break; case Window32Msg.MouseOrigin.PRO_TOUCH: type = PROIs3DShow ? OriginType.PRO_3D_TOUCH : OriginType.PRO_2D_TOUCH; break; case Window32Msg.MouseOrigin.U3D_MOUSE: type = U3dIs3DShow ? OriginType.U3D_3D_MOUSE : OriginType.U3D_2D_MOUSE; break; case Window32Msg.MouseOrigin.U3D_TOUCH: type = U3dIs3DShow ? OriginType.U3D_3D_TOUCH : OriginType.U3D_2D_TOUCH; break; } if (m_LogLevel <= Common.LogLevel.DEBUG) { Common.AppLog.AddFormat(Common.LogLevel.DEBUG, "GCInput.MouseUp", $"Button={arg1.ToString()} OriginType={type.ToString()} point={arg2.X} {arg2.Y}"); } m_msgList.Add(new MsgData(type, data, new API.SPoint(arg2.X, arg2.Y))); }
public static MouseInputData Get(int device, InputDataState state, Vector3 position) { MouseInputData mouseInputData; if (state == InputDataState.PRESSED || !idxToMouseData.ContainsKey(device)) { mouseInputData = new MouseInputData(device, state, position); idxToMouseData[device] = mouseInputData; } else { mouseInputData = idxToMouseData[device]; mouseInputData.duration = Time.time - mouseInputData.startTime; } mouseInputData.state = state; if (state == InputDataState.RELEASED) { mouseInputData.releasedPosition = position; idxToMouseData.Remove(device); } mouseInputData.currentPosition = position; return(mouseInputData); }
void HandleMouseButtonHold(MouseInputData mouseData) { player.OnUsingItemHold(mouseData.device, mouseData.currentPosition); Vector2 offset = mouseData.currentPosition - mouseData.pressedPosition; float duration = mouseData.duration; if (offset.sqrMagnitude < stationaryDeltaSqr) { // Si estamos por debajo de un cierto umbral (para que no registre un gesto rápido como preciso) if (duration > longTouchDuration) { // Si se trata de un touch de larga duración activamos el item 1 if (player.IsActive(1)) { return; } player.OnUsingItemStart(1, mouseData.device, mouseData.currentPosition); } } else { if (player.IsActive(0)) { return; } // En caso de que superemos el umbral se considerará que está usándose el ítem 0 player.OnUsingItemStart(0, mouseData.device, mouseData.currentPosition); } }
public List <IInputData> GetInputs() { var data = new List <IInputData>(); for (int i = 0; i < Input.touchCount; i++) { Touch touch = Input.GetTouch(i); InputDataState inputState; if (touch.phase == TouchPhase.Began) { inputState = InputDataState.PRESSED; } else if (touch.phase == TouchPhase.Ended) { inputState = InputDataState.RELEASED; } else { inputState = InputDataState.HOLD; } data.Add(MouseInputData.Get(i, inputState, touch.position)); } return(data); }
public static void Click(MouseButton button) { foreach (var mouse in MouseInputData.GetClickData(button)) { var input = new INPUT(mouse); SendInput(1, ref input, Marshal.SizeOf <INPUT>()); } }
internal static void DoMouse(MouseEventFlags mouseEventFlags, System.Drawing.Point point) { INPUT input = new INPUT(); MouseInputData mi = new MouseInputData(); input.type = SendInputEventType.InputMouse; input.mkhi.mi = mi; input.mkhi.mi.dwExtraInfo = IntPtr.Zero; input.mkhi.mi.dx = point.X * (65536 / Screen.PrimaryScreen.Bounds.Width); input.mkhi.mi.dy = point.Y * (65536 / Screen.PrimaryScreen.Bounds.Height); input.mkhi.mi.time = 0; input.mkhi.mi.mouseData = 0; input.mkhi.mi.dwFlags = mouseEventFlags; int cbSize = Marshal.SizeOf(typeof(INPUT)); SendInput(1, ref input, cbSize); }
public List <IInputData> GetInputs() { var data = new List <IInputData>(); if (Input.GetKey(KeyCode.RightArrow)) { data.Add(new ButtonInputData(InputButton.RIGHT, InputDataState.HOLD)); } else if (Input.GetKey(KeyCode.LeftArrow)) { data.Add(new ButtonInputData(InputButton.LEFT, InputDataState.HOLD)); } if (Input.GetKeyDown(KeyCode.DownArrow)) { data.Add(new ButtonInputData(InputButton.ROLL, InputDataState.PRESSED)); } if (Input.GetKeyDown(KeyCode.UpArrow) || Input.GetKeyDown(KeyCode.Space)) { data.Add(new ButtonInputData(InputButton.JUMP, InputDataState.PRESSED)); } else if (Input.GetKey(KeyCode.UpArrow) || Input.GetKey(KeyCode.Space)) { data.Add(new ButtonInputData(InputButton.JUMP, InputDataState.HOLD)); } else if (Input.GetKeyUp(KeyCode.UpArrow) || Input.GetKeyUp(KeyCode.Space)) { data.Add(new ButtonInputData(InputButton.JUMP, InputDataState.RELEASED)); } if (Input.GetMouseButtonDown(0)) { data.Add(MouseInputData.Get(0, InputDataState.PRESSED, Input.mousePosition)); } else if (Input.GetMouseButton(0)) { data.Add(MouseInputData.Get(0, InputDataState.HOLD, Input.mousePosition)); } else if (Input.GetMouseButtonUp(0)) { data.Add(MouseInputData.Get(0, InputDataState.RELEASED, Input.mousePosition)); } return(data); }
void HandleGUIEvent(MouseInputData data) { GameObject obj = data.GUIElement; if (obj.CompareTag("UIMovement")) { HandleMouseMovement(data); } else if (obj.CompareTag("UIButtonJump")) { JumpAction(data.state); } else if (obj.CompareTag("UIButtonAttack")) { AttackAction(data.state); } }
void HandleMouseMovement(MouseInputData data) { if (data.state == InputDataState.RELEASED) { GameObject guiElement = data.GUIElement; MoveButton mb = guiElement.GetComponent <MoveButton>(); mb.HideMovementHelp(); return; } if (data.state == InputDataState.PRESSED) { GameObject guiElement = data.GUIElement; MoveButton mb = guiElement.GetComponent <MoveButton>(); mb.ShowMovementHelp(data.pressedPosition.x, movementRadiusOffset); } Vector2 start = data.pressedPosition; Vector2 current = data.currentPosition; Vector2 diff = current - start; float absDiffX = Mathf.Abs(diff.x); float absDiffY = Mathf.Abs(diff.y); // entra aqui si es un movimiento en x if (absDiffX > absDiffY && absDiffX > movementRadiusOffset) { if (diff.x > 0) { MoveRightAction(data.state); } else { MoveLeftAction(data.state); } } }
private void PROTouch(int dwFlags, int screenx, int screeny) { if (m_LogLevel <= Common.LogLevel.DEBUG) { Common.AppLog.AddFormat(Common.LogLevel.DEBUG, "GCInput.PROTouch", ""); } MouseInputData data = new MouseInputData(); data.Get(0).Down = IsTouchPressed(dwFlags); data.Get(0).Up = IsTouchReleased(dwFlags); if (PROIs3DShow) { API.SPoint out1, out2; TouchTransform.TouchPosition(m_projectorMonitorRect, new API.SPoint(screenx, screeny), out out1, out out2); m_msgList.Add(new MsgData(OriginType.PRO_3D_TOUCH, data, new API.SPoint(out1.x, out1.y))); } else { m_msgList.Add(new MsgData(OriginType.PRO_2D_TOUCH, data, new API.SPoint(screenx, screeny))); } }
public InputDataUnion(MouseInputData mouseData) { ki = default(KEYBDINPUT); hi = default(HARDWAREINPUT); mi = mouseData; }
public MsgData(OriginType type, MouseInputData data, API.SPoint point) { m_type = type; m_data = data; m_point = point; }
void HandleMouseButtonPressed(MouseInputData mouseData) { return; }
void HandleMouseButtonReleased(MouseInputData mouseData) { player.OnUsingItemStop(mouseData.device); }
/// <summary> /// 处理消息 输出到帧数据 /// 调用顺序 : 窗口消息=>UI脚本调用输入值=>本脚本Update /// 为了同步状态数据和坐标数据帧 /// </summary> private void UpdateMsg() { m_curFrameInputData.Reset(); //目前没有去接收处理鼠标移动消息 if (m_msgList.Count == 0) { //没有消息: //3D主屏鼠标没有消息 => 没有按压状态改变 => 可能坐标改变 => 继续使用m_curFrameMouseScreenPosition //3D主屏触屏没有消息 => 没有任何变动 //投屏鼠标没有消息 => 没有按压状态改变 => 可能坐标改变 => 继续使用m_curFrameMouseScreenPosition //投屏触屏没有消息 => 没有任何变动 //2D主屏鼠标/触屏 => 更新原生Input状态 => 因为后面使用的也是原生Input.mousePosition if (m_curFrameOriginType == OriginType.U3D_2D_MOUSE || m_curFrameOriginType == OriginType.U3D_2D_TOUCH) { m_curFrameInputData.Get(0).Down = Input.GetMouseButtonDown(0); m_curFrameInputData.Get(1).Down = Input.GetMouseButtonDown(1); m_curFrameInputData.Get(2).Down = Input.GetMouseButtonDown(2); m_curFrameInputData.Get(0).Up = Input.GetMouseButtonUp(0); m_curFrameInputData.Get(1).Up = Input.GetMouseButtonUp(1); m_curFrameInputData.Get(2).Up = Input.GetMouseButtonUp(2); } return; } //可能最后使用的触屏位置 API.SPoint finalPoint = m_msgList[m_msgList.Count - 1].m_point; //过滤 OriginType finalType = m_msgList[m_msgList.Count - 1].m_type; for (int i = m_msgList.Count - 1; i >= 0; i--) { MsgData msg = m_msgList[i]; if (msg.m_type != finalType) { m_msgList.RemoveAt(i); } } MouseInputData finalInput = null; //合并按压数据 foreach (MsgData msg in m_msgList) { if (finalInput == null) { finalInput = msg.m_data; } else { finalInput.Combine(msg.m_data); } } m_msgList.Clear(); //这样干 至少编辑器里能兼容情况下原生输入 if (finalType == OriginType.U3D_2D_MOUSE || finalType == OriginType.U3D_2D_TOUCH) { finalInput.Get(0).Down = Input.GetMouseButtonDown(0); finalInput.Get(1).Down = Input.GetMouseButtonDown(1); finalInput.Get(2).Down = Input.GetMouseButtonDown(2); finalInput.Get(0).Up = Input.GetMouseButtonUp(0); finalInput.Get(1).Up = Input.GetMouseButtonUp(1); finalInput.Get(2).Up = Input.GetMouseButtonUp(2); } //数据源切换补充逻辑 if (m_curFrameOriginType != finalType) { bool pressed0 = m_recordDownInputData.IsPressedAndNoReleased(0); bool pressed1 = m_recordDownInputData.IsPressedAndNoReleased(1); bool pressed2 = m_recordDownInputData.IsPressedAndNoReleased(2); //补充一次释放 if (pressed0) { finalInput.Get(0).Up = true; } if (pressed1) { finalInput.Get(1).Up = true; } if (pressed2) { finalInput.Get(2).Up = true; } } //当前帧输出状态只要有释放状态 重新记录 if (finalInput.Get(0).Down) { m_recordDownInputData.Get(0).Down = true; } if (finalInput.Get(1).Down) { m_recordDownInputData.Get(1).Down = true; } if (finalInput.Get(2).Down) { m_recordDownInputData.Get(2).Down = true; } if (finalInput.Get(0).Up) { m_recordDownInputData.Get(0).Reset(); } if (finalInput.Get(1).Up) { m_recordDownInputData.Get(1).Reset(); } if (finalInput.Get(2).Up) { m_recordDownInputData.Get(2).Reset(); } //同步更新数据 m_curFrameInputData.CopyFrom(finalInput); m_curFrameOriginType = finalType; m_curFrameTouchPosition = finalPoint; if (m_LogLevel <= Common.LogLevel.DEBUG) { Common.AppLog.AddFormat(Common.LogLevel.DEBUG, "GCInput.UpdateMsg", $"curFrameOriginType={m_curFrameOriginType}"); Common.AppLog.AddFormat(Common.LogLevel.DEBUG, "GCInput.UpdateMsg", $"LeftDown={m_curFrameInputData.GetMouseButtonDown(0)} LeftUp={m_curFrameInputData.GetMouseButtonUp(0)}"); } }
public void Combine(MouseInputData data) { leftData.Combine(data.Get(leftData.Button)); rightData.Combine(data.Get(rightData.Button)); middleData.Combine(data.Get(middleData.Button)); }
static extern bool GetCursorPos(out MouseInputData lpPoint);
public static void MouseWheel(MouseWheelDirection direction, int amount) { var wheelInput = new INPUT(MouseInputData.GetWheelData(direction, amount)); SendInput(1, ref wheelInput, Marshal.SizeOf <INPUT>()); }
public static void ReturnPointer(int areaWidth, int areaHeight) { POINT p; GetCursorPos(out p); MouseInputData mi = new MouseInputData(); mi.dx = (p.X * 65535) / areaWidth; mi.dy = (p.Y * 65535) / areaHeight; mi.mouseData = 0; mi.dwFlags = MouseEventFlags.MOUSEEVENTF_MOVE | MouseEventFlags.MOUSEEVENTF_ABSOLUTE; mi.time = 0; mi.dwExtraInfo = IntPtr.Zero; INPUT input = new INPUT(); input.type = SendInputEventType.InputMouse; input.mkhi.mi = mi; SendInput(1, ref input, Marshal.SizeOf(new INPUT())); }
public INPUT(MouseInputData mouseData) { data = new InputDataUnion(mouseData); type = SendInputEventType.InputMouse; }
public void CopyFrom(MouseInputData data) { leftData.CoypFrom(data.Get(leftData.Button)); rightData.CoypFrom(data.Get(rightData.Button)); middleData.CoypFrom(data.Get(middleData.Button)); }