protected override Task OnToolActivateAsync(bool hasMapViewChanged) { _msg.VerboseDebug("OnToolActivateAsync"); MapPropertyChangedEvent.Subscribe(OnPropertyChanged); MapSelectionChangedEvent.Subscribe(OnMapSelectionChanged); EditCompletedEvent.Subscribe(OnEditCompleted); PressedKeys.Clear(); try { return(QueuedTask.Run( () => { OnToolActivatingCore(); if (RequiresSelection) { ProcessSelection(ActiveMapView); } return OnToolActivatedCore(hasMapViewChanged); })); } catch (Exception e) { HandleError($"Error in tool activation ({Caption}): {e.Message}", e); } return(Task.CompletedTask); }
public void Clear() { DownKeys.Clear(); PressedKeys.Clear(); CurrentKeyboardState = default(KeyboardState); PreviousKeyboardState = default(KeyboardState); }
/// <summary> /// Clears state of the keyboard. /// </summary> public void Clear() { PressedKeys.Clear(); LastPressedKeys.Clear(); SimulatedKeys.Clear(); PressTime.Clear(); String = ""; }
public override void UpdateInput(bool isActive) { PressedKeys.Clear(); if (state.IsAnyKeyDown) { foreach (Key k in Enum.GetValues(typeof(Key))) { if (state.IsKeyDown(k)) { PressedKeys.Add(k); } } } }
public virtual void Update() { PressedKeys.Clear(); ReleasedKeys.Clear(); foreach (KeyEventArgs keyEvent in keyEvents) { if (DownKeys.Contains(keyEvent.Key)) { PressedKeys.Add(keyEvent.Key); } else { ReleasedKeys.Add(keyEvent.Key); } } keyEvents.Clear(); }
/// <summary> /// Updates the input system. Should be called once per frame. /// </summary> /// <param name="deltaTime">Time in seconds which has passed since the last frame.</param> public static void Update(float deltaTime) { // TODO: Multiple gamepad support (local multiplayer). // Check for capabilities each second. Reduces GC allocations. if (curCapabilityTimer >= _CAPABILITY_CHECK_TIMER) { for (int i = 0; i < GamePadCapabilities.Length; i++) { GamePadCapabilities[i] = GamePad.GetCapabilities(i); } curCapabilityTimer = 0.0f; } else { curCapabilityTimer += deltaTime; } for (int i = 0; i < GamePadCapabilities.Length; i++) { GamePadStates[i] = GamePadCapabilities[i].IsConnected ? GamePad.GetState(i) : default; } // Clear pressed keys. PressedKeys.Clear(); PressedChars.Clear(); // Update inputs. if (IsActive) { UpdateInputs(deltaTime); } // Clean-up for next frame. oldScrollValue = scrollValue; oldPressedChars.Clear(); }
internal void Update() { PressedKeys.Clear(); ReleasedKeys.Clear(); }
private void onDeactivate(object sender, EventArgs e) { PressedKeys.Clear(); }
public override void GameLogic() { // This runs every frame and handles game logic Player player = (Player)GetObjectByName("Player"); SpriteComponent playerSpriteComp = (SpriteComponent)player.GetComponent("SpriteComponent"); GameObject GameResTextObj = GetUIObjectByName("GameRenderTextObj"); TextComponent GameResTextObjComp = (TextComponent)GameResTextObj.GetComponent("TextComponent"); GameResTextObjComp.SetText("Render Width: " + GameResolutionWidth.ToString() + ", Render Height: " + GameResolutionHeight.ToString()); GameObject WindowSizeTextObj = GetUIObjectByName("WindowSizeTextObj"); TextComponent WindowSizeTextObjComp = (TextComponent)WindowSizeTextObj.GetComponent("TextComponent"); WindowSizeTextObjComp.SetText("Window Width: " + WindowWidth.ToString() + ", Render Height: " + WindowHeight.ToString()); // Handle Key Presses if (PressedKeys.Count > 0) { for (int i = 0; i < PressedKeys.Count; i++) { //Keys currentKeyCode = PressedKeys[i]; //printText(EngineClass.debugType.Debug, PressedKeys[i].ToString()); if (PressedKeys[i] == Keys.W) { player.moveUp(60); //playerSpriteComp.SetImageRotation(Rotation.Up); } // REMOVED S to go down because gravity pulls the player down //else if (PressedKeys[i] == Keys.S || PressedKeys[i] == Keys.Down) //{ // player.moveDown(playerSpeed); // //playerSpriteComp.SetImageRotation(Rotation.Down); //} if (PressedKeys[i] == Keys.A) { player.moveLeft(playerSpeed); playerSpriteComp.SetImageRotation(HRotation.Left, VRotation.Up); } else if (PressedKeys[i] == Keys.D) { player.moveRight(playerSpeed); playerSpriteComp.SetImageRotation(HRotation.Right, VRotation.Up); } if (PressedKeys[i] == Keys.Up) { GlobalCoords[1] += 10; } if (PressedKeys[i] == Keys.Down) { GlobalCoords[1] -= 10; } if (PressedKeys[i] == Keys.Left) { GlobalCoords[0] += 10; } if (PressedKeys[i] == Keys.Right) { GlobalCoords[0] -= 10; } if (PressedKeys[i] == Keys.O) { GlobalScale[0] += (float)0.25; GlobalScale[1] += (float)0.25; //PrintText(debugType.Error, "GlobalScale X = " + GlobalScale[0].ToString() + ", Y = " + GlobalScale[1].ToString()); } else if (PressedKeys[i] == Keys.P) { GlobalScale[0] -= (float)0.25; GlobalScale[1] -= (float)0.25; //PrintText(debugType.Error, "GlobalScale X = " + GlobalScale[0].ToString() + ", Y = " + GlobalScale[1].ToString()); } //printText(debugType.Debug, player.x.ToString()); //printText(debugType.Debug, player.y.ToString()); } PressedKeys.Clear(); // Handle Collision //if (player.GetX() + player.GetWidth() > GetCanvasWidth()) //{ // player.x = GetCanvasWidth() - player.width; //} //else if (player.x < 0) //{ // player.x = 0; //} //if (player.y + player.height > GetCanvasHeight()) //{ // player.y = GetCanvasHeight() - player.height; //} //else if (player.y < 0) //{ // player.y = 0; //} } }
public void Stop() { PressedKeys.Clear(); ReleasedKeys.Clear(); ClickedKeys.Clear(); }
/// <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); } } } }