private void KeyPress(object sender, myKeyEventArgs e) { char ch = e.key.KeyChar; if (char.ToLower(ch) != 'a' && char.ToLower(ch) != 'd' && char.ToLower(ch) != 'r' && char.ToLower(ch) != 'l' && char.ToLower(ch) != 'x' && ch != ' ') { e.Handled = true; } else { //действия switch (char.ToLower(ch)) { case 'a': Move(-1); break; case 'd': Move(1); break; case ' ': Shoot(); break; case 'r': KeyAction?.Invoke(1); break; case 'x': KeyAction?.Invoke(2); break; case 'l': KeyAction?.Invoke(3); break; } } }
private static IntPtr HookCallback(int nCode, IntPtr wParam, IntPtr lParam) { if (nCode >= 0 && (wParam == (IntPtr)WM_KEYDOWN || wParam == (IntPtr)WM_KEYUP)) { int vkCode = Marshal.ReadInt32(lParam); KeyAction?.Invoke(new KeyHookEventArgs((Keys)vkCode, wParam == (IntPtr)WM_KEYDOWN ? KeyType.KEY_DOWN : KeyType.KEY_UP)); } return(CallNextHookEx(_hookID, nCode, wParam, lParam)); }
public void OnUpdate() { if (EventSystem.current.IsPointerOverGameObject()) { return; } if (Input.anyKey) { KeyAction?.Invoke(); } if (MouseAction != null) { CheckMouseAction(); } }
void buttonNumPad_Click(object sender, EventArgs e) { Button buttonNumPad = (Button)sender; String Action = buttonNumPad.Name.Substring(RefButton.Name.Length); handleaction(Action); OKButton.Focus(); if (keyAction != null) { try { ReturnNumber = Math.Round(Convert.ToDouble(textBoxNumPadDisplay.Text), RoundingPrecision + 2, MidpointRounding.AwayFromZero); } catch { } keyAction.Invoke(); } }
public virtual void PerformKey(Keys key, bool released) { if (Disabled) { return; } KeyAction?.Invoke(key, released, this); foreach (UIElement child in Children) { Task.Run(() => { try { child.PerformKey(key, released); } catch { } }); } }
// Update is called once per frame public void OnUpdate() { if (EventSystem.current.IsPointerOverGameObject()) { return; } //리스너 패턴 if (Input.anyKey && KeyAction != null) { KeyAction.Invoke(); } if (MouseAction != null) { if (Input.GetMouseButton(0)) { if (!_pressed) { MouseAction.Invoke(Define.MouseEvent.PointerDown); _pressedTime = Time.time; } MouseAction.Invoke(Define.MouseEvent.Press); _pressed = true; } else { if (_pressed) { if (Time.time < _pressedTime + 0.2f) { MouseAction.Invoke(Define.MouseEvent.Click); } MouseAction.Invoke(Define.MouseEvent.PointerUp); } _pressed = false; _pressedTime = 0f; } } }
protected virtual void Update() { if (gameObject.activeInHierarchy == false) { return; } if (window != null && window.isVisible == false) { return; } if (activationTime <= 0.01f) { if (continous) { if (Input.GetKey(keyCode)) { Activate(); } } else { if (Input.GetKeyDown(keyCode)) { Activate(); } } return; } // Got a timer. // Timer if (Input.GetKey(keyCode)) { _activeTime += Time.deltaTime; visualizer.Repaint(_activeTime, activationTime); } else { // No key, reset timer. _activeTime = 0.0f; _firedInActiveTime = false; visualizer.Repaint(0, 1); } // Timer check if (_activeTime < activationTime) { return; } // Time set, it's activated... if (continous) { if (Input.GetKey(keyCode)) { keyActions.Invoke(); } } else { // Already fired / invoked events? if (_firedInActiveTime) { return; } if (Input.GetKey(keyCode)) { keyActions.Invoke(); _firedInActiveTime = true; } } }
protected void OnKeyAction(KeyActionEventArgs e) { KeyAction?.Invoke(this, e); }
protected virtual void Update() { if (gameObject.activeInHierarchy == false) { return; } if (_window != null && _window.isVisible == false) { return; } var rewiredButton = _helper.player.GetButton(_helper.rewiredActionName); var rewiredButtonDown = _helper.player.GetButtonDown(_helper.rewiredActionName); if (activationTime <= 0.01f) { if (continous) { if (rewiredButton) { Activate(); } } else { if (rewiredButtonDown) { Activate(); } } return; } // Got a timer. float rewiredTimeDown = _helper.player.GetButtonTimePressed(_helper.rewiredActionName); visualizer.Repaint(rewiredTimeDown, 1); // Timer if (rewiredButton == false) { _firedInActiveTime = false; } // Timer check if (rewiredTimeDown < activationTime) { return; } // Time set, it's activated... if (continous) { if (rewiredButton) { keyActions.Invoke(); } } else { // Already fired / invoked events? if (_firedInActiveTime) { return; } if (rewiredButton) { keyActions.Invoke(); _firedInActiveTime = true; } } }
public virtual void ReadPage(IPage page) { if (page is KeyInputEvent) { KeyInputEvent keyEvent = page as KeyInputEvent; if (keyEvent.BindKey.ToString() == JoystickID + "TopFace") { if (OnTopButton != null) { OnTopButton.Invoke(keyEvent.KeyHitState); } } if (keyEvent.BindKey.ToString() == JoystickID + "LeftFace") { if (OnLeftButton != null) { OnLeftButton.Invoke(keyEvent.KeyHitState); } } if (keyEvent.BindKey.ToString() == JoystickID + "RightFace") { if (OnRightButton != null) { OnRightButton.Invoke(keyEvent.KeyHitState); } } if (keyEvent.BindKey.ToString() == JoystickID + "BottomFace") { if (OnBottomButton != null) { OnBottomButton.Invoke(keyEvent.KeyHitState); } } if (keyEvent.BindKey.ToString() == JoystickID + "LeftBump") { if (OnLeftBumper != null) { OnLeftBumper.Invoke(keyEvent.KeyHitState); } } if (keyEvent.BindKey.ToString() == JoystickID + "RightBump") { if (OnRightBumper != null) { OnRightBumper.Invoke(keyEvent.KeyHitState); } } if (keyEvent.BindKey.ToString() == JoystickID + "Start") { if (OnStart != null) { OnStart.Invoke(keyEvent.KeyHitState); } } if (keyEvent.BindKey.ToString() == JoystickID + "Select") { if (OnSelect != null) { OnSelect.Invoke(keyEvent.KeyHitState); } } if (keyEvent.BindKey.ToString() == JoystickID + "Home") { if (OnHome != null) { OnHome.Invoke(keyEvent.KeyHitState); } } if (keyEvent.BindKey.ToString() == JoystickID + "LeftAnalogClick") { if (OnLeftAnalogButton != null) { OnLeftAnalogButton.Invoke(keyEvent.KeyHitState); } } if (keyEvent.BindKey.ToString() == JoystickID + "RightAnalogClick") { if (OnRightAnalogButton != null) { OnRightAnalogButton.Invoke(keyEvent.KeyHitState); } } { // handle customs foreach (KeyValuePair <string, KeyBind> pair in LayoutMap.CustomKeyBind.D) { if (keyEvent.BindKey.ToString() == JoystickID + pair.Key) { if (OnCustomKey != null) { OnCustomKey.Invoke(pair.Key, keyEvent.KeyHitState); } } } } } else if (page is AxisInputEvent) { AxisInputEvent AxisEvent = page as AxisInputEvent; if (AxisEvent.BindKey.ToString() == JoystickID + "LeftAnalog") { if (OnLeftAnalog != null) { OnLeftAnalog.Invoke(new Vector2(AxisEvent.AxisMap[JoystickID + LayoutMap.LeftAnalogAxisX], AxisEvent.AxisMap[JoystickID + LayoutMap.LeftAnalogAxisY])); } } else if (AxisEvent.BindKey.ToString() == JoystickID + "RightAnalog") { if (OnRightAnalog != null) { OnRightAnalog.Invoke(new Vector2(AxisEvent.AxisMap[JoystickID + LayoutMap.RightAnalogAxisX], AxisEvent.AxisMap[JoystickID + LayoutMap.RightAnalogAxisY])); } } else if (AxisEvent.BindKey.ToString() == JoystickID + "DPad") { if (OnDPad != null) { OnDPad.Invoke(new Vector2(AxisEvent.AxisMap[JoystickID + LayoutMap.DirectionAxisX], AxisEvent.AxisMap[JoystickID + LayoutMap.DirectionAxisY])); } } else if (AxisEvent.BindKey.ToString() == JoystickID + "LeftTrigger") { if (OnLeftTrigger != null) { OnLeftTrigger.Invoke(new Vector2(AxisEvent.AxisMap[JoystickID + LayoutMap.LeftTriggerAxis], 0.0f)); } } else if (AxisEvent.BindKey.ToString() == JoystickID + "RightTrigger") { if (OnRightTrigger != null) { OnRightTrigger.Invoke(new Vector2(AxisEvent.AxisMap[JoystickID + LayoutMap.RightTriggerAxis], 0.0f)); } } else { // handle customs foreach (KeyValuePair <string, AxisBind> pair in LayoutMap.CustomAxisBind.D) { if (AxisEvent.BindKey.ToString() == JoystickID + pair.Key) { if (OnCustomAxis != null) { OnCustomAxis.Invoke(pair.Key, new Vector2(AxisEvent.AxisMap[JoystickID + pair.Value.PlatformAxisID], 0.0f)); } } } } } }