public KeyState EventState() { var allPressed = true; foreach (var key in Keys) { if (!PressedKeys.Contains(key)) { allPressed = false; } } if (allPressed && !Down) { Down = true; return(KeyState.DOWN); } if (allPressed && Down) { return(KeyState.Pressed); } if (!allPressed && Down) { Down = false; return(KeyState.Up); } return(KeyState.None); }
public KeyState EventState() { bool allPressed = true; foreach (KeyCode key in Keys) { if (!PressedKeys.Contains(key)) { allPressed = false; } } if (allPressed && !Down) { Down = true; return(KeyState.DOWN); } else if (allPressed && Down) { return(KeyState.PRESSED); } else if (!allPressed && Down) { Down = false; return(KeyState.UP); } return(KeyState.NONE); }
private void OnTimerTick(object sender, EventArgs eventArgs) { this._shotCounter = (this._shotCounter + 1) % _shotInterval; if (_isLeftButtonPressed && this._shotCounter == 0) { _shooted = true; var playerData = _controller.GetPlayerData(); var mousePosition = PointToClient(Cursor.Position); var target = new Point( mousePosition.X + playerData.Location.X - Width / 2, mousePosition.Y + playerData.Location.Y - Height / 2); //Console.WriteLine(mouseEventArgs.Location); _controller.ShootInGame(target); } if (!_shooted) { var turn = Turn.None; foreach (var key in actionKeys) { if (PressedKeys.Contains(key)) { turn = KeyToTurn[key].Copy(); } } _controller.SetTurn(turn); } _shooted = false; _controller.TurnGame(); Invalidate(); }
public void OnKeyDown(PreviewKeyDownEventArgs e) { Handler.KeyInPutHandler(this, e.KeyCode, KeyHandlerAction.Down); if (!PressedKeys.Contains(e.KeyData)) { PressedKeys.Add(e.KeyData); } }
private void keyDown(object sender, KeyEventArgs e) { Key tkKey = getTkKeyFrom(e.KeyCode); if (tkKey != Key.Unknown && !PressedKeys.Contains(tkKey)) { PressedKeys.Add(tkKey); } }
/// <summary> /// Releases the specified virtual key to the window. /// </summary> /// <param name="key">The virtual key to release.</param> public virtual void Release(Keys key) { // Create the tuple var tuple = Tuple.Create(Window.Handle, key); // If the key is pressed with an interval if (PressedKeys.Contains(tuple)) { PressedKeys.Remove(tuple); } }
/// <summary> /// Simulate key release /// </summary> public void KeyRelease(Keys key) { if (PressedKeys.Contains(key)) { PressedKeys.Remove(key); } if (SimulatedKeys.Contains(key)) { SimulatedKeys.Remove(key); } }
/// <summary> /// Simulate key press /// </summary> public void KeyPress(Keys key) { if (!PressedKeys.Contains(key)) { PressedKeys.Add(key); } if (!SimulatedKeys.Contains(key)) { SimulatedKeys.Add(key); } }
private void ScreenClicked(MouseEventArgs e, bool isMouseDown) { if (e.Button == MouseButtons.Left || e.Button == MouseButtons.Right) { ScreenClicked(new Rectangle( renderPanel.ClientRectangle.X, renderPanel.ClientRectangle.Y, renderPanel.ClientRectangle.Width, renderPanel.ClientRectangle.Height), e.X, e.Y, isMouseDown, PressedKeys.Contains(Keys.ControlKey), e.Button == MouseButtons.Left, PressedKeys.Contains(Keys.ShiftKey) && e.Button == MouseButtons.Right); } }
public void OnKeyUp(KeyEventArgs e) { Handler.KeyInPutHandler(this, e.KeyCode, KeyHandlerAction.Up); while (PressedKeys.Contains(e.KeyData)) { PressedKeys.Remove(e.KeyData); } if (e.KeyData != Keys.Space) { return; } Field.AddObject(AddableObjects.Mine, this, MainPlayer.CenterPosition()); var obj = Field.Objects.Last(); obj.Position = obj.Position.Sub(obj.Size.Div(2)); }
private static void Postfix(ref ModifierKeys __result) { var modifiers = ModifierKeys.None; if (PressedKeys.Contains(Key.LeftShift) || PressedKeys.Contains(Key.RightShift)) { modifiers |= ModifierKeys.Shift; } if (PressedKeys.Contains(Key.LeftCtrl) || PressedKeys.Contains(Key.RightCtrl)) { modifiers |= ModifierKeys.Control; } if (PressedKeys.Contains(Key.LeftAlt) || PressedKeys.Contains(Key.RightAlt)) { modifiers |= ModifierKeys.Alt; } __result = modifiers; }
protected override async Task <bool> OnSketchModifiedAsync() { _msg.VerboseDebug("OnSketchModifiedAsync"); if (_updateFeedbackTask != null) { // Still working on the previous update (large poylgons!) // -> Consider using latch (but ensure that the overlay must probably be scheduled properly) return(false); } bool nonDefaultSide = _nonDefaultSideMode || PressedKeys.Contains(_keyToggleNonDefaultSide); bool updated = false; try { if (!PressedKeys.Contains(Key.Space)) { // TODO: Exclude finish sketch by double clicking -> should not calculate preview // E.g. wait for SystemInformation.DoubleClickTime for the second click // and only start if it has not ocvurred _updateFeedbackTask = UpdateFeedbackAsync(nonDefaultSide); updated = await _updateFeedbackTask; } } catch (Exception e) { _msg.Warn("Error generating preview", e); return(false); } finally { _updateFeedbackTask = null; } // Does it make any difference what the return value is? return(updated); }
/// <summary> /// Returns true on the frame that the key was pressed. Triggered once per keystroke /// </summary> public bool CheckPressed(Keys key) { return(PressedKeys.Contains(key) && !LastPressedKeys.Contains(key)); }
private static void Postfix(Key key, ref bool __result) { __result = !PressedKeys.Contains(key); }
/// <summary> /// Has to be called every Update to ensure correct calling /// </summary> public void Update(GameTime gameTime) { // Shift pressed to lastPressed LastPressedKeys = new List <Keys>(PressedKeys); PressedKeys.Clear(); KeyboardState state = Keyboard.GetState(); PressedKeys.AddRange(state.GetPressedKeys()); // Add simulated keys foreach (Keys key in SimulatedKeys) { if (!PressedKeys.Contains(key)) { PressedKeys.Add(key); } } // Get pressed time for gmkeyboard.string // Remove released keys foreach (Keys key in PressTime.Keys.ToList()) { if (!PressedKeys.Contains(key)) { PressTime.Remove(key); } } // Add newly pressed keys to pressTime foreach (Keys key in PressedKeys) { if (!PressTime.ContainsKey(key)) { PressTime.Add(key, -gameTime.ElapsedGameTime.TotalMilliseconds); } } Dictionary <Keys, double> lastPressTime = new Dictionary <Keys, double>(PressTime); TriggeredKeys.Clear(); // Handle KeyboardString foreach (Keys key in PressTime.Keys.ToList()) { // Don't add key to string if it isn't allowed to if (Settings.AddSimulatedKeysToKeyboardString == false) { if (SimulatedKeys.Contains(key)) { break; } } PressTime[key] += gameTime.ElapsedGameTime.TotalMilliseconds; bool shouldFire = false; // Fire if key is just pressed if (PressTime[key] == 0) { shouldFire = true; } // Check if it should refire because key is hold if (PressTime[key] >= Settings.ReFireDelay) { int maxTime = Settings.ReFireDelay + Settings.ReFireInterval * 20; if (PressTime[key] > maxTime) { PressTime[key] -= Settings.ReFireInterval * 20; lastPressTime[key] -= Settings.ReFireInterval * 20; } for (int t = Settings.ReFireDelay; t < maxTime; t += Settings.ReFireInterval) { if (PressTime[key] > t && lastPressTime[key] < t) { shouldFire = true; } } } if (shouldFire) { TriggeredKeys.Add(key); // s = shift pressed? bool s = Check(Keys.LeftShift) | Check(Keys.RightShift); string keyString = key.ToString(); if (Alphabet.Contains(key)) { s = state.CapsLock ? !s : s; // Invert shift if CapsLock is on String += s ? keyString : keyString.ToLower(); } else { bool nl = state.NumLock; switch (key) { case Keys.Space: String += " "; break; case Keys.Back: if (String.Length > 0) { String = String.Substring(0, String.Length - 1); } break; case Keys.D1: String += s ? "!" : "1"; break; case Keys.D2: String += s ? "@" : "2"; break; case Keys.D3: String += s ? "#" : "3"; break; case Keys.D4: String += s ? "$" : "4"; break; case Keys.D5: String += s ? "%" : "5"; break; case Keys.D6: String += s ? "^" : "6"; break; case Keys.D7: String += s ? "&" : "7"; break; case Keys.D8: String += s ? "*" : "8"; break; case Keys.D9: String += s ? "(" : "9"; break; case Keys.D0: String += s ? ")" : "0"; break; case Keys.OemComma: String += s ? "<" : ","; break; case Keys.OemPeriod: String += s ? ">" : "."; break; case Keys.OemQuestion: String += s ? "?" : "/"; break; case Keys.OemSemicolon: String += s ? ":" : ";"; break; case Keys.OemQuotes: String += s ? "\"" : "'"; break; case Keys.OemPipe: String += s ? "|" : "\\"; break; case Keys.OemMinus: String += s ? "_" : "-"; break; case Keys.OemPlus: String += s ? "+" : "="; break; case Keys.OemOpenBrackets: String += s ? "{" : "["; break; case Keys.OemCloseBrackets: String += s ? "}" : "]"; break; case Keys.OemTilde: String += s ? "~" : "`"; break; case Keys.NumPad0: String += nl ? "0" : ""; break; case Keys.NumPad1: String += nl ? "1" : ""; break; case Keys.NumPad2: String += nl ? "2" : ""; break; case Keys.NumPad3: String += nl ? "3" : ""; break; case Keys.NumPad4: String += nl ? "4" : ""; break; case Keys.NumPad5: String += nl ? "5" : ""; break; case Keys.NumPad6: String += nl ? "6" : ""; break; case Keys.NumPad7: String += nl ? "7" : ""; break; case Keys.NumPad8: String += nl ? "8" : ""; break; case Keys.NumPad9: String += nl ? "9" : ""; break; case Keys.Multiply: String += "*"; break; case Keys.Divide: String += "/"; break; case Keys.Add: String += "+"; break; case Keys.Subtract: String += "-"; break; case Keys.Decimal: String += "."; break; case Keys.Enter: String += Settings.ParseEnter ? "\n" : ""; break; case Keys.Tab: String += Settings.ParseTab ? "\t" : ""; break; default: break; } } // Limit Keyboard.String length if (String.Length > Settings.StoreLength) { String = String.Substring(String.Length - Settings.StoreLength); } } } }
private void UpdateText(KeyboardState keyboard) { if (HasFocus) { PressedKeys = (IList <Keys>)keyboard.GetPressedKeys(); foreach (Keys k in PressedKeys) { if (!LastPressedKeys.Contains(k)) { if (Text.Length < MaxTextLength) { switch (k) { case Keys.OemMinus: if (PressedKeys.Contains(Keys.LeftShift) || PressedKeys.Contains(Keys.RightShift)) { Text += '_'; } else { Text += '-'; } break; case Keys.D1: if (PressedKeys.Contains(Keys.LeftShift) || PressedKeys.Contains(Keys.RightShift)) { Text += '!'; } else { Text += '1'; } break; case Keys.D2: if (PressedKeys.Contains(Keys.LeftShift) || PressedKeys.Contains(Keys.RightShift)) { Text += '"'; } else { Text += '2'; } break; case Keys.D3: if (PressedKeys.Contains(Keys.LeftShift) || PressedKeys.Contains(Keys.RightShift)) { Text += '§'; } else { Text += '3'; } break; case Keys.D4: if (PressedKeys.Contains(Keys.LeftShift) || PressedKeys.Contains(Keys.RightShift)) { Text += '$'; } else { Text += '4'; } break; case Keys.D5: if (PressedKeys.Contains(Keys.LeftShift) || PressedKeys.Contains(Keys.RightShift)) { Text += '%'; } else { Text += '5'; } break; case Keys.D6: if (PressedKeys.Contains(Keys.LeftShift) || PressedKeys.Contains(Keys.RightShift)) { Text += '&'; } else { Text += '6'; } break; case Keys.D7: if (PressedKeys.Contains(Keys.LeftShift) || PressedKeys.Contains(Keys.RightShift)) { Text += '/'; } else { Text += '7'; } break; case Keys.D8: if (PressedKeys.Contains(Keys.LeftShift) || PressedKeys.Contains(Keys.RightShift)) { Text += '('; } else { Text += '8'; } break; case Keys.D9: if (PressedKeys.Contains(Keys.LeftShift) || PressedKeys.Contains(Keys.RightShift)) { Text += ')'; } else { Text += '9'; } break; case Keys.D0: if (PressedKeys.Contains(Keys.LeftShift) || PressedKeys.Contains(Keys.RightShift)) { Text += '='; } else { Text += '0'; } break; case Keys.OemSemicolon: if (PressedKeys.Contains(Keys.LeftShift) || PressedKeys.Contains(Keys.RightShift)) { Text += ';'; } else { Text += ','; } break; case Keys.NumPad0: Text += "0"; break; case Keys.NumPad1: Text += "1"; break; case Keys.NumPad2: Text += "2"; break; case Keys.NumPad3: Text += "3"; break; case Keys.NumPad4: Text += "4"; break; case Keys.NumPad5: Text += "5"; break; case Keys.NumPad6: Text += "6"; break; case Keys.NumPad7: Text += "7"; break; case Keys.NumPad8: Text += "8"; break; case Keys.NumPad9: Text += "9"; break; case Keys.OemPeriod: if (PressedKeys.Contains(Keys.LeftShift) || PressedKeys.Contains(Keys.RightShift)) { Text += ":"; } else { Text += '.'; } break; case Keys.Back: if (Text.Length > 0) { Text = Text.Remove(Text.Length - 1); } break; case Keys.LeftShift: break; case Keys.RightShift: break; case Keys.V: if (PressedKeys.Contains(Keys.LeftControl) || PressedKeys.Contains(Keys.RightControl)) { break; //todo } else { goto default; } case Keys.RightControl: case Keys.LeftControl: break; default: if (PressedKeys.Contains(Keys.LeftShift) || PressedKeys.Contains(Keys.RightShift)) { Text += char.ToUpper((char)k); } else { Text += char.ToLower((char)k); } break; } } } } LastPressedKeys = PressedKeys; } TextPosition = Position + new Vector2(Hitbox.Width / 2, Hitbox.Height / 2) - ButtonFont.MeasureString(Text) / 2; NamePosition = Position + new Vector2(0, -TextboxNameFont.MeasureString(TextboxName).Y); }
static public void InputUpdater() { var running = true; var threadLimiterWatch = new Stopwatch(); threadLimiterWatch.Start(); while (running) { Thread.Yield(); if (threadLimiterWatch.ElapsedMilliseconds >= 1) { threadLimiterWatch.Restart(); try { KeyboardState = Keyboard.GetState(); MouseState = Mouse.GetState(); if (KeyboardState.GetPressedKeys().Count() > 0) { foreach (Keys key in KeyboardState.GetPressedKeys()) { if (!PressedKeys.Contains(key)) { PressActions.Enqueue(new KeyValuePair <double, Keys>(AudioManager.GetTime(), key)); PressedKeys.Add(key); if (key == Keys.CapsLock) { CapsLock = !CapsLock; Caps = CapsLock; } if (key == Keys.LeftShift || key == Keys.RightShift) { Caps = !CapsLock; } } } } for (int i = 0; i < PressedKeys.Count; i++) { Keys key = PressedKeys[i]; if (!KeyboardState.IsKeyDown(key)) { // Used if LN handling //keyboardReleases.Enqueue(new KeyValuePair<double, Keys>(time, key)); PressedKeys.RemoveAt(i); i--; if (key == Keys.LeftShift || key == Keys.RightShift) { Caps = CapsLock; } } } if (LastMouseClick.Value == 0 && MouseState.LeftButton == ButtonState.Pressed) { LastMouseClick.Key = MouseState; LastMouseClick.Value = 1; } else if (LastMouseClick.Value == 1 && MouseState.LeftButton == ButtonState.Released) { LastMouseClick.Key = MouseState; LastMouseClick.Value = 2; } } catch { } } } }
/// <summary> /// Checks if a key is pressed /// </summary> public bool Check(Keys key) { return(PressedKeys.Contains(key)); }
/// <summary> /// Checks if a specific key was pressed this frame. /// </summary> /// <param name="key">Key to check.</param> /// <returns>True if the key was pressed.</returns> public static bool KeyCodePressed(Keys key) => PressedKeys.Contains(key);
public bool IsKeyDown(Key key) { return(PressedKeys.Contains(key)); }
/// <summary> /// Check if a key got released. Triggered once per keystroke /// </summary> /// <param name="key"></param> /// <returns></returns> public bool CheckReleased(Keys key) { return(!PressedKeys.Contains(key) && LastPressedKeys.Contains(key)); }
/// <summary> /// Check if a key got pressed or released. Triggered on the falling and rising edge of a keystroke. /// </summary> public bool CheckEdge(Keys key) { return(PressedKeys.Contains(key) ^ LastPressedKeys.Contains(key)); }
protected override KeyStates GetKeyStatesFromSystem(Key key) { return(PressedKeys.Contains(key) ? KeyStates.Down : KeyStates.None); }