/// <summary>
        /// Handler for mouse click event
        /// </summary>
        /// <typeparam name="TMouseEvent">Generic parameter, since keyDown and keyUp events have different type for eventArgs</typeparam>
        private void OnMouseOnButtonEvent <TMouseEvent>(EventSourceEventArgs <TMouseEvent> e, MouseEventType eventType) where TMouseEvent : ButtonEvent
        {
            if (!_hotkeyConditionService.ShouldHandleHotkeyEvent(e.Data))
            {
                return;
            }

            InputResult  inputResult;
            UserInputKey mappedKey = _keyMapper.MapToUserInputKey(e.Data.Button);

            if (eventType == MouseEventType.KeyDown)
            {
                inputResult = _keyHandler.OnKeyDown(mappedKey, ModifierKeys.None);
            }
            else
            {
                inputResult = _keyHandler.OnKeyUp(mappedKey);
            }


            if (inputResult.HasFlag(InputResult.HideFromOtherApplications))
            {
                e.Next_Hook_Enabled = false;
            }
        }
Esempio n. 2
0
        public Panelhandler(Lib.UserInputManager manager, UserInputKey key, KeyPointAction onOpen, KeyPointAction onClose,
                            bool blockEnv = true)
        {
            var openhandler      = new KeyHandler(Layer.Ui, BlockType.None);
            var closehandler     = new KeyHandler(Layer.Ui, BlockType.All);
            var openBlockhandler = blockEnv ? new PointerKeyHandler(Layer.Ui, BlockType.All) : null;

            openhandler.BindKeyAction(key, (data) =>
            {
                manager.RegisterKeyhandler(closehandler);
                manager.RegisterPointerhandler(openBlockhandler);
                manager.UnregisterKeyhandler(openhandler);
            });

            if (null != onOpen)
            {
                openhandler.BindKeyAction(key, onOpen);
            }

            closehandler.BindKeyAction(key, (data) =>
            {
                manager.RegisterKeyhandler(openhandler);
                manager.UnregisterKeyhandler(closehandler);
                manager.UnregisterPointerhandler(openBlockhandler);
            });
            if (null != onClose)
            {
                closehandler.BindKeyAction(key, onClose);
            }

            manager.RegisterKeyhandler(openhandler);
        }
Esempio n. 3
0
        public InputResult OnKeyUp(UserInputKey keyCode)
        {
            if (!IsHandlerEnabled || !_isCameraMovingInAnyDirection)
            {
                return(InputResult.Continue);
            }

            if (_cameraMovementKeys.CameraForwardKeys.Contains(keyCode))
            {
                _isCameraMovingUp = false;
            }
            else if (_cameraMovementKeys.CameraBackKeys.Contains(keyCode))
            {
                _isCameraMovingBack = false;
            }
            else if (_cameraMovementKeys.CameraLeftKeys.Contains(keyCode))
            {
                _isCameraMovingLeft = false;
            }
            else if (_cameraMovementKeys.CameraRightKeys.Contains(keyCode))
            {
                _isCameraMovingRight = false;
            }

            if (!(_isCameraMovingUp || _isCameraMovingBack || _isCameraMovingLeft || _isCameraMovingRight))
            {
                _isCameraMovingInAnyDirection = false;
                _actionLoopService.StopLoopingAction();
            }

            return(InputResult.Continue);
        }
        /// <summary>
        /// Handler for keyboard key press event
        /// </summary>
        private void OnKeyEvent(object sender, EventSourceEventArgs <KeyboardEvent> keyboardEventArgs)
        {
            if (keyboardEventArgs.Data == null)
            {
                return;
            }

            if (!_hotkeyConditionService.ShouldHandleHotkeyEvent(keyboardEventArgs.Data))
            {
                return;
            }


            InputResult?inputResult = null;

            if (keyboardEventArgs.Data.KeyDown != null)
            {
                UserInputKey mappedKey    = _keyMapper.MapToUserInputKey(keyboardEventArgs.Data.KeyDown.Key);
                ModifierKeys modifierKeys = GetModifierKeys();
                inputResult = _keyHandler.OnKeyDown(mappedKey, modifierKeys);
            }
            else if (keyboardEventArgs.Data.KeyUp != null)
            {
                UserInputKey mappedKey = _keyMapper.MapToUserInputKey(keyboardEventArgs.Data.KeyUp.Key);
                inputResult = _keyHandler.OnKeyUp(mappedKey);
            }

            if (inputResult.HasValue && inputResult.Value.HasFlag(InputResult.HideFromOtherApplications))
            {
                keyboardEventArgs.Next_Hook_Enabled = false;
            }
        }
Esempio n. 5
0
 public ReceiveItem(int layer, BlockType block, UserInputKey key, string log)
 {
     Layer = layer;
     Block = block;
     Log   = log;
     Key   = key;
 }
Esempio n. 6
0
        public InputResult OnKeyUp(UserInputKey keyCode)
        {
            if (!IsHandlerEnabled)
            {
                return(InputResult.Continue);
            }

            InputResult inputResult;

            if (_cameraHeightKeys.CameraUpKeys.Contains(keyCode))
            {
                _isCameraMovingUp = false;
                inputResult       = InputResult.StopProcessingEvents | InputResult.HideFromOtherApplications;
            }
            else if (_cameraHeightKeys.CameraDownKeys.Contains(keyCode))
            {
                _isCameraMovingDown = false;
                inputResult         = InputResult.StopProcessingEvents | InputResult.HideFromOtherApplications;
            }
            else
            {
                inputResult = InputResult.Continue;
            }

            if (_actionLoopService.IsLoopingAction && !(_isCameraMovingDown || _isCameraMovingUp))
            {
                _actionLoopService.StopLoopingAction();
            }

            return(inputResult);
        }
Esempio n. 7
0
        public KeyData MakeKeyData(UserInputKey key, float axis)
        {
            var data = dataPool.GetData();

            data.Key  = key;
            data.Axis = axis;
            return(data);
        }
Esempio n. 8
0
        public void KeyMapper_MapMouseKey_ProperlyMapped(ButtonCode input, UserInputKey result)
        {
            IKeyMapper keyMapper = CreateKeyMapper();

            UserInputKey mappedKey = keyMapper.MapToUserInputKey(input);

            Assert.Equal(mappedKey, result);
        }
Esempio n. 9
0
        public InputResult OnKeyDown(UserInputKey keyCode, ModifierKeys modifiers)
        {
            if (!IsHandlerEnabled || modifiers != ModifierKeys.None)
            {
                return(InputResult.Continue);
            }

            InputResult inputResult;
            float       cameraHeight;

            // Mouse scroll requires more effort to scroll as much as regular keys,
            // so we add a multiplier to keep it more consistent with other keys
            const int mouseScrollMultiplier = 3;

            if (_cameraHeightKeys.CameraUpKeys.Contains(keyCode))
            {
                if (keyCode == UserInputKey.MouseScrollDown || keyCode == UserInputKey.MouseScrollUp)
                {
                    cameraHeight  = _gameValueService.GetZCameraPosition();
                    cameraHeight += CameraMovementOffset * mouseScrollMultiplier;
                    _gameValueService.SetZCameraPosition(cameraHeight);
                    inputResult = InputResult.StopProcessingEvents | InputResult.HideFromOtherApplications;
                }
                else
                {
                    _isCameraMovingUp = true;
                    inputResult       = InputResult.StopProcessingEvents | InputResult.HideFromOtherApplications;
                }
            }
            else if (_cameraHeightKeys.CameraDownKeys.Contains(keyCode))
            {
                if (keyCode == UserInputKey.MouseScrollDown || keyCode == UserInputKey.MouseScrollUp)
                {
                    cameraHeight  = _gameValueService.GetZCameraPosition();
                    cameraHeight -= CameraMovementOffset * mouseScrollMultiplier;
                    _gameValueService.SetZCameraPosition(cameraHeight);
                    inputResult = InputResult.StopProcessingEvents | InputResult.HideFromOtherApplications;
                }
                else
                {
                    _isCameraMovingDown = true;
                    inputResult         = InputResult.StopProcessingEvents | InputResult.HideFromOtherApplications;
                }
            }
            else
            {
                inputResult = InputResult.Continue;
            }

            if (!_actionLoopService.IsLoopingAction && (_isCameraMovingDown || _isCameraMovingUp))
            {
                _actionLoopService.StartLoopingAction(MoveCamera);
            }

            return(inputResult);
        }
Esempio n. 10
0
        private KeyData MakeKeyData(UserInputKey key, float axis, Vector3 pos)
        {
            var data = dataPool.GetData();

            data.Key      = key;
            data.Position = pos;
            data.MouseX   = Input.GetAxis("Mouse X");
            data.MouseY   = Input.GetAxis("Mouse Y");
            return(data);
        }
Esempio n. 11
0
        public List <KeyConvertItem> Convert(UserInputKey code)
        {
            List <KeyConvertItem> list;

            if (inputConvertDict.TryGetValue(code, out list))
            {
                return(list);
            }
            return(emptyList);
        }
        public InputResult OnKeyDown(UserInputKey keyCode, ModifierKeys modifiers)
        {
            if (!IsHandlerEnabled)
            {
                return(InputResult.Continue);
            }

            // zoom out
            if (_keys.ZoomOutKeys.Contains(keyCode))
            {
                float zoomValue    = _gameValueService.GetCameraZoomDistance();
                float cameraHeight = _gameValueService.GetZCameraPosition();

                if (!IsTacticalCameraEnabled && zoomValue <= _turnOnTacticalCameraThreshold)
                {
                    _turnOffTacticalCameraThreshold = cameraHeight;
                    EnableTacticalCamera();
                }
                else
                {
                    return(InputResult.Continue);
                }
            }
            else if (_keys.ZoomInKeys.Contains(keyCode))
            {
                float cameraHeight = _gameValueService.GetZCameraPosition();

                if (IsTacticalCameraEnabled)
                {
                    if (cameraHeight < _turnOffTacticalCameraThreshold)
                    {
                        DisableTacticalCamera();
                    }
                }
                else
                {
                    return(InputResult.Continue);
                }
            }
            else if (_keys.ToggleKeys.Contains(keyCode))
            {
                if (IsTacticalCameraEnabled)
                {
                    DisableTacticalCamera();
                    return(InputResult.HideFromOtherApplications);
                }
            }

            return(InputResult.Continue);
        }
Esempio n. 13
0
        /// <inheritdoc/>
        public async Task <UserInputKey> WaitForKeyPress(bool blockPressedKey = false)
        {
            var taskCompletionSource = new TaskCompletionSource <UserInputKey>();

            using (IKeyboardEventSource keyboard = WindowsInput.Capture.Global.KeyboardAsync())
            {
                using (IMouseEventSource mouse = WindowsInput.Capture.Global.MouseAsync())
                {
                    mouse.ButtonScroll += (_, keyEventArgs) =>
                    {
                        if (keyEventArgs?.Data?.Button != null)
                        {
                            UserInputKey mappedKey = _keyMapper.MapToUserInputKey(keyEventArgs.Data.Offset);
                            if (blockPressedKey)
                            {
                                keyEventArgs.Next_Hook_Enabled = false;
                            }
                            taskCompletionSource.SetResult(mappedKey);
                        }
                    };
                    mouse.ButtonDown += (_, keyEventArgs) =>
                    {
                        if (keyEventArgs?.Data?.Button != null && keyEventArgs.Data.Button != ButtonCode.VScroll && keyEventArgs.Data.Button != ButtonCode.HScroll)
                        {
                            UserInputKey mappedKey = _keyMapper.MapToUserInputKey(keyEventArgs.Data.Button);
                            if (blockPressedKey)
                            {
                                keyEventArgs.Next_Hook_Enabled = false;
                            }
                            taskCompletionSource.SetResult(mappedKey);
                        }
                    };
                    keyboard.KeyEvent += (_, keyEventArgs) =>
                    {
                        if (keyEventArgs?.Data?.KeyDown != null)
                        {
                            UserInputKey mappedKey = _keyMapper.MapToUserInputKey(keyEventArgs.Data.KeyDown.Key);
                            if (blockPressedKey)
                            {
                                keyEventArgs.Next_Hook_Enabled = false;
                            }
                            taskCompletionSource.SetResult(mappedKey);
                        }
                    };

                    return(await taskCompletionSource.Task.ConfigureAwait(false));
                }
            }
        }
Esempio n. 14
0
        public KeyHandler BindKeyAction(UserInputKey key, KeyPointAction pointAction)
        {
            var            data = new KeyData(key);
            KeyPointAction actionAss;

            if (binding.TryGetValue(data, out actionAss))
            {
                actionAss += pointAction;
            }
            else
            {
                binding[data] = pointAction;
            }
            return(this);
        }
Esempio n. 15
0
        public PointerKeyHandler BindPointAction(UserInputKey key, KeyPointAction action)
        {
            var            data = new PointerData(key);
            KeyPointAction pointActions;

            if (binding.TryGetValue(data, out pointActions))
            {
                pointActions += action;
            }
            else
            {
                binding[data] = action;
            }
            return(this);
        }
Esempio n. 16
0
        /// <summary>
        /// Handler for mouse scroll event. Does not affect clicks
        /// </summary>
        private void OnMouseScroll(object sender, EventSourceEventArgs <ButtonScroll> mouseEventArgs)
        {
            if (!_hotkeyConditionService.ShouldHandleHotkeyEvent(mouseEventArgs.Data))
            {
                return;
            }

            UserInputKey mappedKey   = _keyMapper.MapToUserInputKey(mouseEventArgs.Data.Offset);
            InputResult? inputResult = _keyHandler.OnKeyDown(mappedKey, ModifierKeys.None);

            if (inputResult.Value.HasFlag(InputResult.HideFromOtherApplications))
            {
                mouseEventArgs.Next_Hook_Enabled = false;
            }
        }
Esempio n. 17
0
        public InputResult OnKeyDown(UserInputKey keyCode, ModifierKeys modifiers)
        {
            if (!IsHandlerEnabled || modifiers != ModifierKeys.None)
            {
                return(InputResult.Continue);
            }

            InputResult inputResult;

            if (_cameraMovementKeys.CameraForwardKeys.Contains(keyCode))
            {
                _isCameraMovingUp = true;
                inputResult       = InputResult.HideFromOtherApplications | InputResult.StopProcessingEvents;
            }
            else if (_cameraMovementKeys.CameraBackKeys.Contains(keyCode))
            {
                _isCameraMovingBack = true;
                inputResult         = InputResult.HideFromOtherApplications | InputResult.StopProcessingEvents;
            }
            else if (_cameraMovementKeys.CameraLeftKeys.Contains(keyCode))
            {
                _isCameraMovingLeft = true;
                inputResult         = InputResult.HideFromOtherApplications | InputResult.StopProcessingEvents;
            }
            else if (_cameraMovementKeys.CameraRightKeys.Contains(keyCode))
            {
                _isCameraMovingRight = true;
                inputResult          = InputResult.HideFromOtherApplications | InputResult.StopProcessingEvents;
            }
            else
            {
                inputResult = InputResult.Continue;
            }

            if (!_actionLoopService.IsLoopingAction &&
                (_isCameraMovingUp || _isCameraMovingBack || _isCameraMovingLeft || _isCameraMovingRight))
            {
                _isCameraMovingInAnyDirection = true;
                _actionLoopService.StartLoopingAction(MoveCamera);
            }

            return(inputResult);
        }
Esempio n. 18
0
        public InputResult OnKeyDown(UserInputKey keyCode, ModifierKeys modifiers)
        {
            if (!IsHandlerEnabled)
            {
                return(InputResult.Continue);
            }

            if (_tacticalCameraToggleKeys.Contains(keyCode))
            {
                if (!IsTacticalCameraEnabled && IsHandlerEnabled)
                {
                    EnableTacticalCamera();
                }
                else
                {
                    DisableTacticalCamera();
                }
            }

            return(InputResult.Continue);
        }
 public void SendKeyDown(UserInputKey key)
 {
     BitConverter.GetBytes((ushort)key).CopyTo(buffer, HEADER_LENGTH + 0);
     SendCommand(OP_BUTTON_PRESS, 2);
 }
Esempio n. 20
0
        private bool RaycastSonar(float distance, out RaycastHit hitTarget, UserInputKey inputKey)
        {
            try
            {
                PlayerEntity playerEntity = player.flagSelfEntity;
                var          ray          = Camera.main.ScreenPointToRay(Input.mousePosition);
                var          headRay      = new Ray(playerEntity.position.Value, playerEntity.RootGo().transform.forward);
                var          angle        = 15;
                if (playerEntity.appearanceInterface.Appearance.IsFirstPerson)
                {
                    angle = 35;
                }
                float      angleCos  = Mathf.Cos(Mathf.Deg2Rad * angle);
                GameObject resultObj = null;
                float      maxDot    = 0f;

                Collider[] cols = Physics.OverlapSphere(ray.origin, distance, _raycastMask);
                foreach (Collider col in cols)
                {
                    float dot = dirDot(ray, col.transform.position);
                    if (dot < angleCos)
                    {
                        continue;
                    }
                    float headDot = dirDot(headRay, col.transform.position);
                    if (headDot < 0)
                    {
                        continue;
                    }
                    var rcTar = col.gameObject.GetComponentInParent <RayCastTarget>();
                    if (null == rcTar || !rcTar.KeyList.Contains(inputKey))
                    {
                        continue;
                    }
                    if (null == resultObj)
                    {
                        resultObj = col.gameObject;
                        maxDot    = dot;
                    }
                    else
                    {
                        if (dot > maxDot)
                        {
                            resultObj = col.gameObject;
                            maxDot    = dot;
                        }
                    }
                }

                if (null != resultObj)
                {
                    Vector3 dir = resultObj.transform.position - ray.origin;
                    if (Physics.Raycast(ray.origin, dir, out hitTarget, dir.magnitude, _raycastMask))
                    {
                        if (hitTarget.transform.gameObject == resultObj)
                        {
                            return(true);
                        }
                        else
                        {
                            var rcTar = hitTarget.transform.GetComponentInParent <RayCastTarget>();
                            if (null != rcTar && rcTar.KeyList.Contains(inputKey))
                            {
                                return(true);
                            }
                            else
                            {
                                return(false);
                            }
                        }
                    }
                }
            }
            catch (Exception e)
            {
                _logger.ErrorFormat("{0}", e);
            }
            hitTarget = new RaycastHit();
            return(false);
        }
Esempio n. 21
0
 public KeyData(UserInputKey key, float axis)
 {
     Key  = key;
     Axis = axis;
 }
Esempio n. 22
0
 public KeyData(UserInputKey key)
 {
     Key = key;
 }
Esempio n. 23
0
 public PointerData(UserInputKey key) : base(key)
 {
     Position = Vector3.zero;
 }
Esempio n. 24
0
 public PointerData(UserInputKey key, Vector3 position) : base(key)
 {
     Position = position;
 }
 public InputResult OnKeyUp(UserInputKey keyCode)
 {
     return(InputResult.Continue);
 }
Esempio n. 26
0
        private bool GetHitTarget(float distance, out RaycastHit hitTarget, UserInputKey inputKey)
        {
            hitTarget = new RaycastHit();
            try
            {
                var ray          = Camera.main.ScreenPointToRay(Input.mousePosition);
                int resultsCount = Physics.RaycastNonAlloc(ray, results, distance > 0.01f ? distance : _maxRaycastDistance, _raycastMask);

                if (resultsCount == 0)
                {
                    return(false);
                }

                bool hasC4 = false;
                for (int i = 0; i < resultsCount; i++)
                {
                    var raycastHit = results[i];
                    var keyTarget  = raycastHit.transform.GetComponent <RayCastTarget>();
                    //忽略不可操作的物体
                    if (keyTarget == null || !keyTarget.KeyList.Contains(inputKey))
                    {
                        ignoreHit.Add(raycastHit);
                    }
                    else
                    {
                        if (keyTarget.IdList.Count >= 3 && keyTarget.IdList[2] == 46)
                        {
                            hitTarget = raycastHit;
                            hasC4     = true;
                            break;
                        }
                        //忽略玩家装备的武器、配件的触发盒,避免玩家触发范围比实际大很多
                        if (raycastHit.collider.gameObject.layer == UnityLayerManager.GetLayerIndex(EUnityLayerName.Player) &&
                            raycastHit.collider.gameObject.name.ToLower().Equals("NormalCollider".ToLower()))
                        {
                            ignoreHit.Add(raycastHit);
                        }
                    }
                }

                if (ignoreHit.Count == resultsCount)
                {
                    return(false);
                }

                if (!hasC4)
                {
                    for (int i = 0; i < resultsCount; i++)
                    {
                        var raycastHit = results[i];
                        if (!ignoreHit.Contains(raycastHit))
                        {
                            if (hitTarget.distance <= 0f || IsFirstCloserToSecond(raycastHit, hitTarget))
                            {
                                hitTarget = raycastHit;
                            }
                        }
                    }
                }
            }
            catch (Exception e)
            {
                _logger.ErrorFormat("{0}", e);
                return(false);
            }

            return(true);
        }