/// <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; } }
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); }
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; } }
public ReceiveItem(int layer, BlockType block, UserInputKey key, string log) { Layer = layer; Block = block; Log = log; Key = key; }
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); }
public KeyData MakeKeyData(UserInputKey key, float axis) { var data = dataPool.GetData(); data.Key = key; data.Axis = axis; return(data); }
public void KeyMapper_MapMouseKey_ProperlyMapped(ButtonCode input, UserInputKey result) { IKeyMapper keyMapper = CreateKeyMapper(); UserInputKey mappedKey = keyMapper.MapToUserInputKey(input); Assert.Equal(mappedKey, result); }
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); }
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); }
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); }
/// <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)); } } }
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); }
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); }
/// <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; } }
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); }
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); }
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); }
public KeyData(UserInputKey key, float axis) { Key = key; Axis = axis; }
public KeyData(UserInputKey key) { Key = key; }
public PointerData(UserInputKey key) : base(key) { Position = Vector3.zero; }
public PointerData(UserInputKey key, Vector3 position) : base(key) { Position = position; }
public InputResult OnKeyUp(UserInputKey keyCode) { return(InputResult.Continue); }
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); }