public string Convert(Keys[] keys) { string output = ""; bool usesShift = (keys.Contains(Keys.LeftShift) || keys.Contains(Keys.RightShift)); foreach (Keys key in keys) { if (key >= Keys.A && key <= Keys.Z) output += key.ToString(); else if (key >= Keys.NumPad0 && key <= Keys.NumPad9) output += ((int)(key - Keys.NumPad0)).ToString(); else if (key >= Keys.D0 && key <= Keys.D9) { string num = ((int)(key - Keys.D0)).ToString(); output += num; } else if(key == Keys.Space) { output += " "; } else if(key == Keys.OemPeriod) { output += "."; } if (!usesShift) output = output.ToLower(); } return output; }
/// <summary> /// Removes the value with the provided key. /// </summary> /// <param name="key">The key of the value to remove.</param> public void RemoveStateValue(string key) { string fullKey = GetStateKey(groupKey, key); // Remove the key if (Keys.Contains(key)) { Keys.Remove(key); } switch (Scope) { case StateScope.Application: StateAccess.State.RemoveApplication(fullKey); break; case StateScope.Session: StateAccess.State.RemoveSession(fullKey); break; case StateScope.Operation: StateAccess.State.RemoveOperation(fullKey); break; } }
internal void Add(string fileName) { if (!Keys.Contains(fileName)) { Add(fileName, fileName); } }
/// <summary> /// Add Value with complex Id-Name key to collection. /// </summary> /// <param name="id"></param> /// <param name="name"></param> /// <param name="value"></param> public void Add(TId id, TName name, TValue value) { if (id == null) { throw new ArgumentNullException(nameof(id)); } if (name == null) { throw new ArgumentNullException(nameof(name)); } if (value == null) { throw new ArgumentNullException(nameof(value)); } var keyToAdd = new KeyStruct(id, name); if (Keys.Contains(keyToAdd)) { throw new KeyAlreadyExistsException($"Key: {id} - {name} already exists"); } try { lock (_locker) { _dictionary.Add(keyToAdd, value); SaveKeyPairHelper(id, name); } } catch (Exception) { throw new CollectionException($"Key: {id} - {name} adding error"); } }
public virtual void AddKey(string key) { if (!Keys.Contains(key)) { Keys.Add(key); } }
public bool Remove(Tkey key) { if (!Keys.Contains(key)) { return(false); } if (Count == 0) { return(false); } if (key.Equals(this.key)) { if (left == null && rigth == null) // Нет левого и правого дерева { this.key = default; value = default; } else if (left == null && rigth != null) // Только правое { this.key = rigth.key; value = rigth.value; left = rigth.left; rigth = rigth.rigth; } else if (left != null && rigth == null) // Только левое { this.key = left.key; value = left.value; left = left.left; rigth = left.rigth; } else // Есть обе ветки { var newElement = _FindLeftElement(rigth); if (newElement.rigth == null) { this.key = newElement.key; value = newElement.value; var father = _FindFather(key, this); father.left = null; } else { this.key = newElement.key; value = newElement.value; var father = _FindFather(key, this); father.left = newElement.rigth; } } } else if (this.key.CompareTo(key) < 0) { left.Remove(key); } else { rigth.Remove(key); } return(true); }
/// <summary> /// Gets or sets the value associated with the specified key. /// </summary> /// <param name="key">The key of the value to get or set.</param> /// <returns>The value associated with the specified key. If the specified key is not found, /// a get operation throws a System.Collections.Generic.KeyNotFoundException, and /// a set operation creates a new element with the specified key (I know SerializableDictionary doesn't use a collection, but shut up).</returns> /// <exception cref="KeyNotFoundException">The Keys array does not contain key</exception> public TValue this[TKey key] { get { if (Keys.Contains(key)) { for (int i = 0; i < Keys.Count; i++) { if (Keys[i].Equals(key)) { return(Values[i]); } } } throw new KeyNotFoundException(); } set { if (Keys.Contains(key)) { for (int i = 0; i < Keys.Count; i++) { if (Keys[i].Equals(key)) { Values[i] = value; } } } else { Add(key, value); } } }
private bool IsControlKeyCode(Keys key) { Keys[] listControllKey = new Keys[] { Keys.Enter, Keys.LControlKey , Keys.RControlKey, Keys.LWin, Keys.RWin, Keys.RMenu, Keys.LMenu , Keys.LShiftKey, Keys.RShiftKey, Keys.Tab , Keys.Left, Keys.Right , Keys.Down, Keys.Up , Keys.F10, Keys.F1 , Keys.F2, Keys.F3 , Keys.F4, Keys.F5 , Keys.F6, Keys.F7 , Keys.F8, Keys.F9 , Keys.F11, Keys.F12 , Keys.Escape, Keys.Delete , Keys.PageDown, Keys.Home , Keys.PageUp, Keys.End , Keys.Scroll, Keys.Pause , Keys.Insert, Keys.Next , Keys.CapsLock, Keys.Capital , Keys.Apps }; if (listControllKey.Contains(key)) { return(true); } return(false); }
private void GlControl1_KeyDown(object sender, KeyEventArgs e) { // Проверка, чтобы не было введено запрещённых действий, например, движение другого игрока var currentPlayerControl = this.gameConfig.Player.Control; var currentPlayerActions = new Keys[] { currentPlayerControl.Down, currentPlayerControl.Up, currentPlayerControl.Left, currentPlayerControl.Right, currentPlayerControl.Fire, currentPlayerControl.FireMiniGun, }; var isKeyValidForThisApplication = currentPlayerActions.Contains(e.KeyCode); if (!isKeyValidForThisApplication) { return; } // Обработка ввода gameActionService.ProcessPlayerAction(e.KeyCode); //SendKeyToOpponent(e.KeyCode); SendMessageToCPP(e.KeyCode); glControl1.Invalidate(); }
/// <summary> /// Adds value to a container /// Добавить значения в контэйнер /// </summary> /// <param name="name">The name of data</param> /// <param name="value">The value of data</param> public void AddValues(string name, object value) { if ((value != null) && (value.GetType() == typeof(List <string>))) { int index = 1; foreach (string str in ((List <string>)value)) { if (Keys.Contains(name + index)) { this[name + index] = str; } else { this.Add(name + index, str); } index++; } } //if (this.Keys.Contains(name)) //{ // this[name] = value; //} //else //{ // this.Add(name, value); //} }
public valueT this[keyT index] { get { var idx = Keys.IndexOf(index); if (idx < 0) { return(default(valueT)); } return(Values[idx]); } set { if (Keys.Contains(index)) { var idx = Keys.IndexOf(index); Values[idx] = value; return; } var i = 0; for (i = 0; i < Keys.Count; i++) { if (Keys[i].CompareTo(index) * ((int)this.PriorityOrder) > 0) { break; } } Keys.Insert(i, index); Values.Insert(i, value); } }
/// <summary>Determines whether the specified value of the object is valid.</summary> /// <param name="value">The value of the object to validate.</param> /// <returns>True if the specified value is valid; otherwise, false.</returns> public override bool IsValid(object value) { if (value != null) { var values = value as IEnumerable <object>; if ((values == null && SelectionType == SelectionType.None) || SelectionType == SelectionType.Single) { return(string.IsNullOrEmpty(value.ToString()) || Keys.Contains(value)); } if (values != null && (SelectionType == SelectionType.None || SelectionType == SelectionType.Multiple)) { foreach (var v in values) { if (!(string.IsNullOrEmpty(v.ToString()) || Keys.Contains(v))) { return(false); } } } } return(true); }
/// <summary>Fixed the update.</summary> public override void FixedUpdate() { for (int i = 0; i < KeyboardsValues.Length; i++) { TempKey = Enum.Parse <SFML.Window.Keyboard.Key>(KeyboardsNames[i]); if (SFML.Window.Keyboard.IsKeyPressed(TempKey)) { if (!Keys.Contains(KeyboardsValues[i])) { Keys.Add(KeyboardsValues[i]); PressDown(KeyboardsValues[i]); OnPressDownKey.Invoke(this, KeyboardsValues[i]); } PressKey(KeyboardsValues[i]); OnPressKey.Invoke(this, KeyboardsValues[i]); } else { if (Keys.Contains(KeyboardsValues[i])) { Keys.Remove(KeyboardsValues[i]); PressUp(KeyboardsValues[i]); OnReleaseKey.Invoke(this, KeyboardsValues[i]); } } } }
/// <summary> /// Shows the menu items and return the user's choice /// </summary> /// <returns>string with the user selected option</returns> public string Show() { var tokenizer = new AcceleratorCharTokenizer(); int i = 0; Keys.Clear(); foreach (var item in Items) { if (Options.NumerationStyle == MenuNumeration.AcceleratorKey) { Console.WriteLine(tokenizer.Parse(item)); Keys.Add(GetAcceleratorChar(item).ToString()); } else { (string key, IEnumerable <ColorToken> tokens) = ComposeMenuItem(i, item); Console.WriteLine(tokens); Keys.Add(key); } i++; } Console.Ask(BuildMessage()); string value = Console.ReadLine <string>(x => IsDefaultValue(x) || Keys.Contains(x)); return(IsDefaultValue(value) ? Options.DefaultItem : value); }
private void Guard() { if (Keys == null || Keys.Count == 0 || Keys.Contains(null)) { throw new DiscordDiceException($"{nameof(CommandOption)}.{nameof(Keys)} に問題があります。"); } }
/// <summary> /// Sets the provided value in the state to correspond with the provided key, in the scope indicated by the Scope property, and in the group indicated by the GroupKey property. /// </summary> /// <param name="key">The key to assign to the provided value.</param> /// <param name="value">The value to save to state along with the provided key, prefixed by scope and group key.</param> public void SetStateValue(string key, T value) { string fullKey = GetStateKey(groupKey, key); switch (Scope) { case StateScope.Application: StateAccess.State.SetApplication(fullKey, value); break; case StateScope.Session: StateAccess.State.SetSession(fullKey, value); break; case StateScope.Operation: StateAccess.State.SetOperation(fullKey, value); break; } if (value == null) { // Remove the key Keys.Remove(key); RemoveStateValue(key); } else { if (!Keys.Contains(key)) { Keys.Add(key); } } }
public T GetData <T>(String pk, T def) { if (Keys.Contains(pk) && this[pk] is T) { return((T)this[pk]); } return(def); }
public void Remove(TKey key) { if (!Keys.Contains(key)) { return; } kvpList.RemoveAt(Keys.IndexOf(key)); }
/// <summary> /// Checks if the cache contains the key /// </summary> /// <param name="key">Key to check</param> /// <returns>True if it is there, false otherwise</returns> public override bool ContainsKey(string key) { if (HttpContext.Current == null) { return(false); } return(Keys.Contains(key)); }
/// <summary> /// Determines whether the <see cref="T:System.Collections.Generic.IDictionary`2"/> /// contains an element with the specified key. /// </summary> /// <param name="key">The key to locate in the <see cref="T:System.Collections.Generic.IDictionary`2"/>.</param> /// <returns> /// true if the <see cref="T:System.Collections.Generic.IDictionary`2"/> contains an element with the key; otherwise, false. /// </returns> /// <exception cref="T:System.ArgumentNullException"> /// <paramref name="key"/> is null. /// </exception> public bool ContainsKey(string key) { if (key == null) { throw new ArgumentNullException("key"); } return(Keys.Contains(key)); }
private string ValueOf(string key) { if (!Keys.Contains(key)) { ThrowException(key); } return(_match.Groups[key].Value); }
public Tvalue this[TKey key] { get { if (Keys.Contains(key)) { return(base[Keys.IndexOf(key)].Value); } return(default);
/// <summary> /// Bind a default value to a key to prevent uninitialized properties /// </summary> /// <param name="key">The key to initialize</param> /// <param name="value">The value</param> public void SetDefaultValue(string key, string value) { // If the variable does not exist yet, initialize and save if (!Keys.Contains(key)) { Add(key, value); Save(); } }
protected void Add(string key, Vector2 value) { if (Keys.Contains(key)) { return; } Keys.Add(key); Values.Add(value); }
public bool ContainsKey(string key) { if (Constants.ContentType.Equals(key, StringComparison.OrdinalIgnoreCase)) { return(!string.IsNullOrEmpty(_response.ContentType)); } return(Keys.Contains(key, StringComparer.OrdinalIgnoreCase)); }
public T Get <T>(string key, T defaultValue) { if (!Keys.Contains(key)) { return(defaultValue); } return(UniversalConverter.ConvertTo(this[key].ObjectValue, defaultValue)); }
public bool Remove(string key) { if (!Keys.Contains(key)) { return(false); } _actual.Remove(key); return(true); }
public static bool KeyIsWritable(Keys key) { var keysNotWrite = new Keys[] { Keys.ControlKey, Keys.Alt, Keys.ShiftKey, Keys.LShiftKey, Keys.RShiftKey, Keys.Menu, Keys.LMenu, Keys.RMenu, Keys.Apps, Keys.CapsLock, Keys.Control, Keys.VolumeDown, Keys.VolumeMute, Keys.VolumeUp, Keys.XButton1, Keys.XButton2, Keys.Zoom, Keys.Attn, Keys.Capital, Keys.F1, Keys.F2, Keys.F3, Keys.F4, Keys.F5, Keys.F6, Keys.F7, Keys.F8, Keys.F9, Keys.F10, Keys.F11, Keys.F12, Keys.F13, Keys.F14, Keys.F15, Keys.F16, Keys.F17, Keys.F18, Keys.F19, Keys.F20, Keys.F21, Keys.F22, Keys.F23, Keys.F24, Keys.LWin, Keys.RWin, Keys.Escape, Keys.Down, Keys.Up, }; return(!keysNotWrite.Contains(key)); }
public Tvalue this[Tkey key] { get { if (!Keys.Contains(key)) { throw new KeyNotFoundException(); } if (key.Equals(this.key)) { return(value); } else if (this.key.CompareTo(key) < 0) //Левая ветка { return(left[key]); } else { return(rigth[key]); } } set { if (FirstElementFlag) { this.key = key; this.value = value; FirstElementFlag = false; } else if (this.key.CompareTo(key) < 0) { if (left != null) { left[key] = value; } else { left = new BinaryTreeDictionary <Tkey, Tvalue>(); left[key] = value; } } else { if (rigth != null) { rigth[key] = value; } else { rigth = new BinaryTreeDictionary <Tkey, Tvalue>(); rigth[key] = value; } } } }
public bool TryGetValue(TKey key, out TValue value) { if (!Keys.Contains(key)) { value = default(TValue); return(false); } value = Values[Keys.IndexOf(key)]; return(true); }
/// <summary> /// Permite apenas numeros /// </summary> /// <param name="e"></param> public static void OnlyDigits(KeyEventArgs e) { Keys[] digits = new Keys[] { Keys.D0, Keys.D1, Keys.D2, Keys.D3, Keys.D4, Keys.D5, Keys.D6, Keys.D7, Keys.D8, Keys.D9, Keys.Back, Keys.Left, Keys.Right, Keys.Up, Keys.Down, Keys.NumPad0, Keys.NumPad1, Keys.NumPad2, Keys.NumPad3, Keys.NumPad4, Keys.NumPad5, Keys.NumPad6, Keys.NumPad7, Keys.NumPad8, Keys.NumPad9 }; if (!digits.Contains(e.KeyData)) { e.SuppressKeyPress = true; } }
public override async void Put(string key, string value) { if (!Keys.Contains(key)) { Keys.Add(key); } await _innerStorage.PutAsync(key, value); await _innerStorage.PutAsync(_indexName, Keys); }
public void Move(Keys[] keys) { if (keys.Contains(Keys.Up) && keys.Contains(Keys.Right)) { this.position.Y -= this.velocity / 2; this.position.X += this.velocity / 2; } else if (keys.Contains(Keys.Right) && keys.Contains(Keys.Down)) { this.position.Y += this.velocity / 2; this.position.X += this.velocity / 2; } else if (keys.Contains(Keys.Down) && keys.Contains(Keys.Left)) { this.position.Y += this.velocity / 2; this.position.X -= this.velocity / 2; } else if (keys.Contains(Keys.Left) && keys.Contains(Keys.Up)) { this.position.Y -= this.velocity / 2; this.position.X -= this.velocity / 2; } else if (keys.Contains(Keys.Left)) { this.position.X -= this.velocity; } else if (keys.Contains(Keys.Up)) { this.position.Y -= this.velocity; } else if (keys.Contains(Keys.Down)) { this.position.Y += this.velocity; } else if (keys.Contains(Keys.Right)) { this.position.X += this.velocity; } }
public void KeyPressed(Keys[] pressedKeys) { if (pressedKeys.Length == 0) { nonePressed = true; upPressed = false; leftPressed = false; downPressed = false; rightPressed = false; } else { nonePressed = false; if (pressedKeys.Contains(Keys.W)) { upPressed = true; } else { upPressed = false; } if (pressedKeys.Contains(Keys.A)) { leftPressed = true; } else { leftPressed = false; } if (pressedKeys.Contains(Keys.S)) { downPressed = true; } else { downPressed = false; } if (pressedKeys.Contains(Keys.D)) { rightPressed = true; } else { rightPressed = false; } } }
private void Move(Keys[] keys) { if (IsOnGround() && (keys.Contains(Keys.Space) || keys.Contains(Keys.Up) || keys.Contains(Keys.W))) { Jump(); } Directions lateralDirection = Directions.None; if (keys.Contains(Keys.Right) || keys.Contains(Keys.D)) { lateralDirection |= Directions.Right; } if (keys.Contains(Keys.Left) || keys.Contains(Keys.A)) { lateralDirection |= Directions.Left; } Move(lateralDirection); }
public static void onKeys(Keys[] pressedKeys) { if (pressedKeys.Contains(Keys.N) && !previousKeys.Contains(Keys.N)) { //Do something if N was just pressed; } if (pressedKeys.Contains(Keys.G) && !previousKeys.Contains(Keys.G)) { //Main.godMode = !Main.godMode; // not working atm //Main.player[Main.myPlayer].immune = true; if (Main.player[Main.myPlayer].immuneTime < 0) { Main.player[Main.myPlayer].immuneTime = 1000000; } // works, but dangerous, since immunetime <> 0 when taking hit else Main.player[Main.myPlayer].immuneTime = 0; } previousKeys = pressedKeys; }
internal void KeyPressed(Keys[] keys) { #region Player control keys if (keys.Contains(Keys.W)) player.PlayerPressedKey(Keys.W); if (keys.Contains(Keys.A)) player.PlayerPressedKey(Keys.A); if (keys.Contains(Keys.D)) player.PlayerPressedKey(Keys.D); if (keys.Contains(Keys.Q)) player.PlayerPressedKey(Keys.Q); if (keys.Contains(Keys.Escape)) game.states.setCurrentState(StateManager.State.Menu); if (keys.Contains(Keys.LeftShift)) player.SetSprinting(true); // SHIFT - Sprint. else if (!keys.Contains(Keys.LeftShift)) player.SetSprinting(false); //Stop Sprint #endregion }
public void TypeInto(Keys[] keys) { m_text += Convert(keys); if(keys.Contains(Keys.Enter)) { if (m_text.Length > 13 && m_text.Substring(0, 13) == "set bg color ") CheckIfColor(); if(m_text.Length > 13 && m_text.Substring(0, 13) == "set ball spd ") CheckIfSpeed(); if(m_text.Length >= 9 && m_text.Substring(0, 9) == "stop ball") Game1.SetBallSpeed(0f); } }
public HResult SetKeys(INiCommandBarButton button, Keys[] keys) { try { if (button == null) throw new ArgumentNullException("button"); if (keys == null) throw new ArgumentNullException("keys"); foreach (var key in keys) { if (!ShortcutKeysUtil.IsValid(key)) throw new ArgumentException(String.Format("{0} is not a valid shortcut", key)); } var id = button.Id; List<Keys> currentKeys; if (!_mappingsByButton.TryGetValue(id, out currentKeys)) { currentKeys = new List<Keys>(); _mappingsByButton.Add(id, currentKeys); } // Remove the button from keys that are not set anymore. foreach (var key in currentKeys) { if (!keys.Contains(key)) { List<Guid> buttons; if (_mappingsByKeys.TryGetValue(key, out buttons)) { bool removed = buttons.Remove(id); Debug.Assert(removed); } else { Debug.Fail("Expected key to appear in mapping"); } } } // Add the button to new keys. foreach (var key in keys) { if (!currentKeys.Contains(key)) { List<Guid> buttons; if (!_mappingsByKeys.TryGetValue(key, out buttons)) { buttons = new List<Guid>(); _mappingsByKeys.Add(key, buttons); } buttons.Add(id); } } // Save the new key bindings. currentKeys.Clear(); currentKeys.AddRange(keys); // Update the new mappings with the new keys. if (AreSameKeys(_keyboardMappingManager._initialKeys[id], keys)) Mappings.Remove(id); else Mappings[id] = keys.ToArray(); return HResult.OK; } catch (Exception ex) { return ErrorUtil.GetHResult(ex); } }
public void ManagePlayerStates(Character player, Keys[] pressedkeys, int stagelimit) { if (player.HasState(State.DYING)) return; if (player.CurrentHealth <= 0 || player.Position.Y > stagelimit) { player.CurrentHealth = 0; player.AddState(State.ALIVE); player.AddState(State.DYING); return; } int dx = 0, dy = 0; //Here we manage Horizontal movement if (pressedkeys.Contains<Keys>(Keys.Left)) { dx -= 5; player.RemoveState(State.FACERIGHT); player.AddState(State.FACELEFT); player.AddState(State.MOVING); } else if (pressedkeys.Contains<Keys>(Keys.Right)) { dx += 5; player.RemoveState(State.FACELEFT); player.AddState(State.FACERIGHT); player.AddState(State.MOVING); } else player.RemoveState(State.MOVING); //Here we manage vertical movement based on jumping actions if (pressedkeys.Contains<Keys>(Keys.Up)) { if (player.HasState(State.JUMPING)) { if (player.Position.Y < player.MaxHeight) { dy = (int)player.Position.Y - player.MaxHeight; player.RemoveState(State.JUMPING); player.AddState(State.FALLING); } else dy -= 15; } if (player.HasState(State.STANDING)) { player.MaxHeight = ((int)player.Position.Y - 200); if (player.MaxHeight < 0) player.MaxHeight = 0; player.RemoveState(State.STANDING); player.AddState(State.JUMPING); dy -= 3; } } else { if (player.HasState(State.JUMPING)) { player.AddState(State.FALLING); player.RemoveState(State.JUMPING); } } dy += 5; player.Move(dx, dy); }
private void getMove(KeyboardState keyState) { // If there is a selected tile. if (0 <= selectedTile.X && 0 <= selectedTile.Y) { // Keyboard Keys[] pressedKeys = keyState.GetPressedKeys(); Keys[] numPadKeys = new Keys[] {Keys.NumPad1, Keys.NumPad2, Keys.NumPad3, Keys.NumPad4, Keys.NumPad5, Keys.NumPad6, Keys.NumPad7, Keys.NumPad8, Keys.NumPad9, Keys.NumPad0, Keys.D1, Keys.D2, Keys.D3, Keys.D4, Keys.D5, Keys.D6, Keys.D7, Keys.D8, Keys.D9, Keys.D0}; for (int keyIndex = 0; keyIndex < pressedKeys.Length; ++keyIndex) { if (keyState.IsKeyDown(pressedKeys[keyIndex]) && oldKeyState.IsKeyUp(pressedKeys[keyIndex]) && numPadKeys.Contains(pressedKeys[keyIndex])) { int value = (Array.IndexOf(numPadKeys, pressedKeys[keyIndex]) % 10) + 1; // Remove value from crossout. if (pressedKeys.Contains(Keys.Space) && value != 10) { // Remove value from crossout. if (crossout[selectedTile].Contains(value)) { crossout[selectedTile].Remove(value); // Add value to crossout. } else { crossout[selectedTile].Add(value); } hasMoved = true; // Change selected tile to value pressed. } else if ((value == 10 || crossout[selectedTile].Contains(value) == false) && curBoard.Original[selectedTile.X, selectedTile.Y] == 0) { curBoard[selectedTile.X, selectedTile.Y] = value % 10; hasMoved = true; } } } // Mouse for (int i = 0; i < moveBoardDest.GetLength(0); ++i) { for (int j = 0; j < moveBoardDest.GetLength(1); ++j) { // If right mouse clicked or left mouse + spacebar, then crossout value from possible values. int value = moveBoard[i, j]; // Crossout value from possible values. if ((moveBoardDest[i, j].Contains(lastClickedLeft) && pressedKeys.Contains(Keys.Space)) || moveBoardDest[i, j].Contains(lastClickedRight)) { // If have value, remove value. if (crossout[selectedTile].Contains(value)) { crossout[selectedTile].Remove(value); // Else, add value. } else { crossout[selectedTile].Add(value); } // Change selected tile to value pressed. } else if (moveBoardDest[i, j].Contains(lastClickedLeft) && crossout[selectedTile].Contains(value) == false && curBoard.Original[selectedTile.X, selectedTile.Y] == 0) { curBoard[selectedTile.X, selectedTile.Y] = value; } } } } }
public void Fly(Keys[] keys) { if (keys.Contains(Keys.Tab)) { if (keys.Contains(Keys.Up) && keys.Contains(Keys.Right)) { this.Position.Y -= this.FlightSpeeds.Y / 2; this.Position.X += this.FlightSpeeds.X / 2; } else if (keys.Contains(Keys.Right) && keys.Contains(Keys.Down)) { this.Position.Y += this.FlightSpeeds.Y / 2; this.Position.X += this.FlightSpeeds.X / 2; } else if (keys.Contains(Keys.Down) && keys.Contains(Keys.Left)) { this.Position.Y += this.FlightSpeeds.Y / 2; this.Position.X -= this.FlightSpeeds.X / 2; } else if (keys.Contains(Keys.Left) && keys.Contains(Keys.Up)) { this.Position.Y -= this.FlightSpeeds.Y / 2; this.Position.X -= this.FlightSpeeds.X / 2; } else if (keys.Contains(Keys.Left)) { this.Position.X -= this.FlightSpeeds.X; } else if (keys.Contains(Keys.Up)) { this.Position.Y -= this.FlightSpeeds.Y; } else if (keys.Contains(Keys.Down)) { this.Position.Y += this.FlightSpeeds.Y; } else if (keys.Contains(Keys.Right)) { this.Position.X += this.FlightSpeeds.X; } } }
bool IsValidChar(Keys key) { Keys[] invalid = new Keys[] { Keys.Left, Keys.Right, Keys.Up, Keys.Down, Keys.Back, Keys.Delete, Keys.BrowserBack, Keys.LeftShift, Keys.LeftAlt, Keys.LeftControl, Keys.LeftWindows, Keys.Enter, Keys.Escape, Keys.RightAlt }; if (invalid.Contains(key)) return false; char c = KeyCodeToChar(key); return !Char.IsControl(c); }
public override void Update(GameTime gameTime) { kbd = Keyboard.GetState(); if (show) { if (kbd.IsKeyDown(Keys.C) && prevKbd.IsKeyUp(Keys.C) && kbd.IsKeyDown(Keys.LeftControl)) { Close(); return; } if (cursor_blink < CURSOR_BLINK_DELAY_MS) cursor_blink += gameTime.ElapsedGameTime.Milliseconds; if (cursor_blink > CURSOR_BLINK_DELAY_MS) { drawCursor = !drawCursor; cursor_blink = 0; } if (kbd.IsKeyDown(Keys.Left) && prevKbd.IsKeyUp(Keys.Left)) cursorOffset = Math.Max(0, cursorOffset - 1); else if (kbd.IsKeyDown(Keys.Right) && prevKbd.IsKeyUp(Keys.Right)) cursorOffset = Math.Min(inputBuffer.Length, cursorOffset + 1); else if (IsPressed(Keys.Up)) { int started = cursorOffset; while (cursorOffset > inputBuffer.Length - 1) cursorOffset--; while (cursorOffset > 0 && inputBuffer[cursorOffset] != '\n') cursorOffset--; int lineOffset = started - cursorOffset; if (cursorOffset > 0) cursorOffset--; while (cursorOffset > 0 && inputBuffer[cursorOffset] != '\n') cursorOffset--; cursorOffset += lineOffset; } else if (IsPressed(Keys.Down)) { int started = cursorOffset; while (cursorOffset > inputBuffer.Length - 1) cursorOffset--; while (cursorOffset > 0 && inputBuffer[cursorOffset] != '\n') cursorOffset--; int lineOffset = started - cursorOffset; cursorOffset = Math.Min(inputBuffer.Length - 1, cursorOffset + lineOffset + 1); while (cursorOffset < inputBuffer.Length - 1 && inputBuffer[cursorOffset] != '\n') cursorOffset++; cursorOffset = Math.Min(cursorOffset + lineOffset, inputBuffer.Length - 1); } else if (IsPressed(Keys.End)) { while (cursorOffset < inputBuffer.Length - 1 && inputBuffer[cursorOffset] != '\n') cursorOffset++; } else if (IsPressed(Keys.Home)) { while (cursorOffset > inputBuffer.Length - 1) cursorOffset--; while (cursorOffset > 0 && inputBuffer[cursorOffset] != '\n') cursorOffset--; } else if (IsPressed(Keys.F5)) { var result = eval.Evaluate(inputBuffer.ToString()); if (result.Success) Close(); lastResult = result; } else { Keys[] keys = kbd.GetPressedKeys(); if (keys.Length > 0 && (int)keys[0] > 0 || keys.Length > 1) { Keys[] skip = new Keys[] { Keys.LeftShift, Keys.LeftControl, Keys.LeftAlt, Keys.None }; Keys key = (from k in keys where !skip.Contains(k) && prevKbd.IsKeyUp(k) select k).FirstOrDefault(); bool shift = kbd.IsKeyDown(Keys.LeftShift); bool alt = kbd.IsKeyDown(Keys.RightAlt); if (IsPressed(Keys.Delete)) { if (kbd.IsKeyDown(Keys.LeftControl)) { cursorOffset = 0; inputBuffer.Clear(); } else if (cursorOffset >= 0 && cursorOffset < inputBuffer.Length) { inputBuffer.Remove(cursorOffset, 1); } } else if (IsPressed(Keys.Back)) { if (inputBuffer.Length >= 0 && cursorOffset > 0) { inputBuffer.Remove(cursorOffset - 1, 1); cursorOffset = Math.Max(cursorOffset - 1, 0); } } else if (key == Keys.Tab && prevKbd.IsKeyUp(Keys.Tab)) { inputBuffer.Append(" "); cursorOffset += 2; } else if (key == Keys.Enter && prevKbd.IsKeyUp(Keys.Enter) && cursorOffset > 0) { inputBuffer.Insert(cursorOffset, '\n'); cursorOffset++; } else if (IsPressed(Keys.D) && kbd.IsKeyDown(Keys.LeftControl)) { // Delete Complete Line while (cursorOffset > inputBuffer.Length - 1) cursorOffset--; while (cursorOffset > 0 && inputBuffer[cursorOffset] != '\n') { inputBuffer.Remove(cursorOffset, 1); cursorOffset--; } } else if (IsValidChar(key) && IsPressed(key)) { char ch = KeyCodeToChar(key, shift, alt); if (cursorOffset >= inputBuffer.Length) { inputBuffer.Append(ch); } else { inputBuffer.Insert(cursorOffset, ch); //inputBuffer[cursorOffset] = ch; } cursorOffset++; } cursorPos.X = CURSOR_START_X + cursorOffset * CURSOR_WIDTH; } } } else if (showNextTime) { show = true; showNextTime = false; } prevKbd = kbd; base.Update(gameTime); }
public string Convert(Keys[] keys) { string output = ""; bool usesShift = (keys.Contains(Keys.LeftShift) || keys.Contains(Keys.RightShift)); foreach (Keys key in keys) { //thanks SixOfEleven @ DIC if (prevState.IsKeyUp(key)) continue; if (key >= Keys.A && key <= Keys.Z) output += key.ToString(); else if (key >= Keys.NumPad0 && key <= Keys.NumPad9) output += ((int)(key - Keys.NumPad0)).ToString(); else if (key >= Keys.D0 && key <= Keys.D9) { string num = ((int)(key - Keys.D0)).ToString(); #region special num chars if (usesShift) { switch (num) { case "1": { num = "!"; } break; case "2": { num = "@"; } break; case "3": { num = "#"; } break; case "4": { num = "$"; } break; case "5": { num = "%"; } break; case "6": { num = "^"; } break; case "7": { num = "&"; } break; case "8": { num = "*"; } break; case "9": { num = "("; } break; case "0": { num = ")"; } break; default: //wtf? break; } } #endregion output += num; } else if (key == Keys.OemPeriod) output += "."; else if (key == Keys.OemTilde) output += "'"; else if (key == Keys.Space) output += " "; else if (key == Keys.OemMinus) output += "-"; else if (key == Keys.OemPlus) output += "+"; else if (key == Keys.OemQuestion && usesShift) output += "?"; else if (key == Keys.Back) //backspace output += "\b"; if (!usesShift) //shouldn't need to upper because it's automagically in upper case output = output.ToLower(); } return output; }