private KeyboardHook() { _callbacks = new Dictionary <HotKey, Action>(); _window = new Window(); // register the event of the inner native window. _window.KeyPressed += (key) => KeyPressed?.Invoke(key); }
/// <summary> /// Blocking function that should be called in a while loop. /// </summary> public void HandleEventLoop() { var character = Console.ReadKey(); var ev = new KeyPressEvent { Key = character, State = MakeApplicationState() }; KeyPressed?.Invoke(this, ev); if (ev.Cancel) { return; } ActiveComponent.HandleKeyPress(this, ev); if (ev.State.ActiveComponent != ActiveComponent) { ev.Rerender = Focus(ev.State.ActiveComponent) || ev.Rerender; } if (ev.Rerender) { Render(); } }
private void OnKeyDown(object sender, IKeyboardHookEventArgs e) { if (IsKeyPressed(e.Key)) { return; } var isModifier = false; if (_leftModifierMappings.TryGetValue(e.Key, out var modifier)) { _leftModifiers = _leftModifiers | modifier; Modifiers = Modifiers | _leftModifiers; isModifier = true; } else if (_rightModifierMappings.TryGetValue(e.Key, out modifier)) { _rightModifiers = _rightModifiers | modifier; Modifiers = Modifiers | _rightModifiers; isModifier = true; } _pressed.Add(e.Key); var args = new KeyTrackerEventArgs { Handled = e.Handled, Key = e.Key, IsModifier = isModifier }; KeyPressed?.Invoke(this, args); e.Handled = args.Handled; }
private void RaisePressedEvents(GameTime gameTime, KeyboardState currentState) { if (!currentState.IsKeyDown(Key.AltLeft) && !currentState.IsKeyDown(Key.AltRight)) { var pressedKeys = Enum.GetValues(typeof(Key)) .Cast <Key>() .Where(key => currentState.IsKeyDown(key) && _previousState.IsKeyUp(key)); foreach (var key in pressedKeys) { var args = new KeyboardEventArgs(key, currentState); KeyPressed?.Invoke(this, args); if (args.Character.HasValue) { KeyTyped?.Invoke(this, args); } _previousKey = key; _lastPressTime = gameTime.TotalGameTime; _isInitial = true; } } }
protected override void WndProc(ref Message m) { base.WndProc(ref m); if (m.Msg != WM_HOTKEY) { return; } Keys key = (Keys)(((int)m.LParam >> 16) & 0xFFFF); ModifierKeys modifier = (ModifierKeys)((int)m.LParam & 0xFFFF); if ((modifier & ModifierKeys.Alt) == ModifierKeys.Alt) { key = key | Keys.Alt; } if ((modifier & ModifierKeys.Control) == ModifierKeys.Control) { key = key | Keys.Control; } if ((modifier & ModifierKeys.Shift) == ModifierKeys.Shift) { key = key | Keys.Shift; } KeyPressed?.Invoke(this, new KeyPressedEventArgs(key)); }
private void KeyPressedHandler(KeyPressed message) { Entity?playerEntity = World.Entities.FirstOrDefault(f => f.Has <Player>()); if (playerEntity is null) { return; } var transform = playerEntity.Get <Transform>(); var rigidbody = playerEntity.Get <Rigidbody>(); var player = playerEntity.Get <Player>(); switch (message.Key) { case Keys.Z: rigidbody.Velocity -= new Vector2(0f, -1f).Rotate(transform.Rotation) * ShootImpact; World.Send(new SpawnBullet { Position = transform.Position, Rotation = transform.Rotation }); break; case Keys.X when player.LasersCount > 0: player.LasersCount--; World.Send(new SpawnBullet { BulletType = BulletType.Laser, Position = transform.Position, Rotation = transform.Rotation }); break; } }
public void CheckInput() { if (DateTimeOffset.Now.ToUnixTimeMilliseconds() - millis > DELAY) { Key?key = null; dispatcher.Invoke(DispatcherPriority.Normal, (Action) delegate { if (Keyboard.IsKeyDown(Key.Up)) { key = Key.Up; } else if (Keyboard.IsKeyDown(Key.Down)) { key = Key.Down; } else if (Keyboard.IsKeyDown(Key.Left)) { key = Key.Left; } else if (Keyboard.IsKeyDown(Key.Right)) { key = Key.Right; } else if (Keyboard.IsKeyDown(Key.Escape)) { key = Key.Escape; } }); if (key != null) { millis = DateTimeOffset.Now.ToUnixTimeMilliseconds(); KeyPressed?.Invoke(this, new Tetris.Data.KeyEventArgs(keyMap[(Key)key])); } } }
public void StartDetector() { if (!IsKeyThreadRunning) { IsKeyThreadRunning = true; new Thread(() => { while (true) { for (int i = 0; i < KeysCodesToHandle.Count; i++) { VirtualKeyCode key = KeysCodesToHandle[i]; if (input.InputDeviceState.IsKeyDown(key)) { Task.Run(() => KeyDown?.Invoke(key)); } if (IsKeyPressed(input.InputDeviceState, key)) { Task.Run(() => KeyPressed?.Invoke(key)); } } Thread.Sleep(8); } }).Start(); } }
public void HandleKeyDown(int player_index, KeyPressed key) { if (!KeysDown.Contains(key)) { KeysDown.Add(key); } }
public StateBowlerHatReThrow(int itemIndex, BoxingPlayer player, KeyPressed key) : base(player, "BowlerRethrow") { canCatch = true; itemButton = key; }
/// <summary> /// Get user input. /// IOleCommandTarget.Exec() function /// </summary> public int Exec(ref Guid pguidCmdGroup, uint nCmdID, uint nCmdexecopt, IntPtr pvaIn, IntPtr pvaOut) { Debug.WriteLine($"InputListener.Exec( {pguidCmdGroup} {nCmdID} {nCmdexecopt} {pvaIn} {pvaOut} )"); ThreadHelper.ThrowIfNotOnUIThread(); int hr = VSConstants.S_OK; if ((new[] { 4, // tab 7, // left arrow 11, // up arrow 9, // right arrow 13, // down arrow 103, // escape 32, // space }).Contains((int)nCmdID)) { // send '\0' so we can abort KeyPressed?.Invoke(this, new KeyPressEventArgs('\0')); return(hr); } char typedChar; if (TryGetTypedChar(pguidCmdGroup, nCmdID, pvaIn, out typedChar)) { KeyPressed?.Invoke(this, new KeyPressEventArgs(typedChar)); return(hr); } ThreadHelper.ThrowIfNotOnUIThread(); hr = nextCommandHandler.Exec(ref pguidCmdGroup, nCmdID, nCmdexecopt, pvaIn, pvaOut); return(hr); }
public KeyboardHook() { // register the event of the inner native window. window.KeyPressed += delegate(object sender, KeyPressedEventArgs args) { KeyPressed?.Invoke(this, args); }; }
public void HandleKeyRelease(int player_index, KeyPressed key) { if (KeysDown.Contains(key)) { KeysDown.Remove(key); } }
public void Poll() { foreach (var keyPair in RegisteredKeys.ToList()) { var key = keyPair.Key; var modifiersDown = true; var modifiers = Keys.None; if (key.HasFlag(Keys.Shift)) { modifiersDown &= IsKeyDown(Keys.ShiftKey); modifiers |= Keys.Shift; } if (key.HasFlag(Keys.Control)) { modifiersDown &= IsKeyDown(Keys.ControlKey); modifiers |= Keys.Control; } if (key.HasFlag(Keys.Alt)) { modifiersDown &= IsKeyDown(Keys.Menu); modifiers |= Keys.Alt; } var keyWithoutModifiers = key & ~modifiers; var result = GetAsyncKeyState(keyWithoutModifiers); var isPressed = ((result >> 15) & 1) == 1; var wasPressedBefore = keyPair.Value; RegisteredKeys[key] = isPressed; if (modifiersDown && isPressed && !wasPressedBefore) { KeyPressed?.Invoke(this, new KeyEventArgs(key)); } } }
public void CheckInput() { if (Console.KeyAvailable) { ConsoleKeyInfo k = Console.ReadKey(true); if (k.Key == ConsoleKey.UpArrow) { KeyPressed?.Invoke(this, new KeyEventArgs(KeyEventArgs.Keys.RotateL)); } else if (k.Key == ConsoleKey.DownArrow) { KeyPressed?.Invoke(this, new KeyEventArgs(KeyEventArgs.Keys.Down)); } else if (k.Key == ConsoleKey.LeftArrow) { KeyPressed?.Invoke(this, new KeyEventArgs(KeyEventArgs.Keys.Left)); } else if (k.Key == ConsoleKey.RightArrow) { KeyPressed?.Invoke(this, new KeyEventArgs(KeyEventArgs.Keys.Right)); } else if (k.Key == ConsoleKey.Escape) { KeyPressed?.Invoke(this, new KeyEventArgs(KeyEventArgs.Keys.Exit)); } } }
/// <summary> /// Call this inside the OnGUI function of the class to check for any events. /// </summary> public void ProcessEvents() { var eventType = Event.current.type; if (_mouseEventMap.ContainsKey(eventType)) { _mouseEventMap[eventType].ForEach(x => x.InvokeSafe()); } if (eventType == EventType.KeyDown) { KeyPressed.InvokeSafe(new EditorKeyboardEvent()); // TODO: Replace with delete command. There is one...somewhere...apparently...*shrug* if (Event.current.keyCode == KeyCode.Backspace) { DeletePressed.InvokeSafe(); } } if (eventType == EventType.KeyUp) { KeyPressed.InvokeSafe(new EditorKeyboardEvent()); } MousePosition = Event.current.mousePosition; }
private void Key_0_Click(object sender, RoutedEventArgs e) { Button button = (Button)sender; string content = button.Content as string; if (this.Text == null) { this.Text = ""; } string key = content; if (key == "Delete") { if (this.Text.Length > 0) { this.Text = this.Text.Substring(0, this.Text.Length - 1); // 删除最后一位 } } else if (key == "Enter") { key = "\r"; } else { this.Text += key; } KeyPressed?.Invoke(this, new KeyPressedEventArgs { Key = key[0] }); }
/// <summary> /// Handles the KeyPressed event of the <see cref="GameBase.RenderWindow"/>. /// </summary> /// <param name="sender">The source of the event.</param> /// <param name="e">The <see cref="SFML.Window.KeyEventArgs"/> instance containing the event data.</param> void rw_KeyPressed(object sender, KeyEventArgs e) { if (KeyPressed != null) { KeyPressed.Raise(this, e); } }
public override void PressesBegan(NSSet <UIPress> presses, UIPressesEvent evt) { base.PressesBegan(presses, evt); var pressesList = presses.ToArray().ToList(); var firstPress = pressesList.FirstOrDefault(); if (firstPress != null) { var keyCode = KeyCode.Unknown; switch (firstPress.Key.KeyCode) { case UIKeyboardHidUsage.KeyboardUpArrow: keyCode = KeyCode.UpArrow; break; case UIKeyboardHidUsage.KeyboardDownArrow: keyCode = KeyCode.DownArrow; break; } if (keyCode != KeyCode.Unknown) { KeyPressed?.Invoke(this, new KeyPressEventArgs(keyCode, firstPress.Key.Characters)); } } }
private void OnKeyPressed(object sender, Key key) { // add to our table of key pressed this frame keysPressed.Add(key); KeyPressed?.Invoke(sender, key); }
/// <summary> /// Adds the specified mouse keycode to the list of pressed keys. /// </summary> /// <param name="keyCode">The keycode to add.</param> /// <param name="hold">The minimum time to hold keys.</param> public static void AddPressedElement(int keyCode, int hold) { lock (pressedKeys) { EnsureStopwatchRunning(); var time = keyHoldStopwatch.ElapsedMilliseconds; // Invoke the key pressed event asynchronously, since we don't want any slow subscribers to delay // updating the state. Task.Run(() => KeyPressed?.Invoke(keyCode, time)); TryToggleStateKey(keyCode, hold); if (pressedKeys.TryGetValue(keyCode, out var pressed)) { pressed.startTime = time; pressed.removed = false; pressedKeys[keyCode] = pressed; } else { pressedKeys.Add( keyCode, new KeyPress { startTime = keyHoldStopwatch.ElapsedMilliseconds, removed = false }); updated = true; } } }
private HotkeyHook() { _window.KeyPressed += delegate(object sender, KeyPressedEventArgs args) { KeyPressed?.Invoke(this, args); }; }
public KeyboardHook() { _window.KeyPressed += delegate(object sender, KeyPressedEventArgs args) { KeyPressed?.Invoke(this, args); }; }
/// <summary> /// Get user input. /// IOleCommandTarget.Exec() function /// </summary> public int Exec(ref Guid pguidCmdGroup, uint nCmdID, uint nCmdexecopt, IntPtr pvaIn, IntPtr pvaOut) { int hr = VSConstants.S_OK; var x = new[] { 1, 4 }; if ((new[] { 4, // tab 7, // left arrow 11, // up arrow 9, // right arrow 13, // down arrow 103, // escape }).Contains((int)nCmdID)) { // send '\0' so we can abort KeyPressed?.Invoke(this, new KeyPressEventArgs('\0')); return(hr); } char typedChar; if (TryGetTypedChar(pguidCmdGroup, nCmdID, pvaIn, out typedChar)) { KeyPressed?.Invoke(this, new KeyPressEventArgs(typedChar)); return(hr); } hr = nextCommandHandler.Exec(ref pguidCmdGroup, nCmdID, nCmdexecopt, pvaIn, pvaOut); return(hr); }
public virtual void ChangeIndex(int playerIndex, KeyPressed key) { //Debug.WriteLine("Key Pressed = " + key); // When the up or down event is fired, move the index. if (key == KeyPressed.Up) { soundMenu.Play(); Index--; } else if (key == KeyPressed.Down) { soundMenu.Play(); Index++; } if (key == KeyPressed.Attack1) { if (OnEntrySelect != null) { OnEntrySelect(entries[Index]); } } }
private void LateUpdate() { if (Time.time - _prevMoveTime > _moveDelay) { _prevMoveTime = Time.time; if (Input.GetKey(KeyCode.A)) { KeyPressed.SafeInvoke(PlayerAction.MOVE_LEFT); } if (Input.GetKey(KeyCode.D)) { KeyPressed.SafeInvoke(PlayerAction.MOVE_RIGHT); } } if (Input.GetKeyDown(KeyCode.W)) { KeyPressed.SafeInvoke(PlayerAction.ROTATE); } if (Input.GetKey(KeyCode.S)) { KeyPressed.SafeInvoke(PlayerAction.MOVE_DOWN); } #if KEY_DEBUG if (!string.IsNullOrEmpty(Input.inputString)) { Debugger.Log(LogEntryCategory.Input, $"The {Input.inputString.ToUpper()} key was pressed"); } #endif }
private void InvokeKeyPressed(Keys key) { if (KeyPressed != null) { KeyPressed.Invoke(this, new KeyPressedEventArgs(key)); } }
public bool OnKeyPressed(ConsoleKeyInfo cki) { KeyEventArgs e = new KeyEventArgs(cki); KeyPressed?.Invoke(this, e); return(!e.Cancel); }
private void ReadThreadProc() { try { byte[] lastKeyStates = new byte[NumKeys + 1]; while (!_cancellationTokenSource.IsCancellationRequested) { try { var keyStates = ReadKeyStates(); if (keyStates != null && keyStates.Length > 0) { for (int keyIdx = 1; keyIdx <= NumKeys; keyIdx++) { if (keyStates[keyIdx] != lastKeyStates[keyIdx]) { KeyPressed?.Invoke(this, new StreamDeckKeyChangedEventArgs(ConvertKeyIndex(keyIdx - 1), keyStates[keyIdx] > 0)); } } lastKeyStates = keyStates; } } catch (Exception ex) { Trace.TraceError($"ReadThreadProc had failure: {ex}"); } } } catch (Exception ex) { Trace.TraceInformation($"ReadThreadProc exiting due to FAILURE: {ex}"); } }
/// <summary> /// Constructor for the keyboard shortcuts class. /// </summary> public HotKeyMap() { _window.KeyPressed += delegate(object sender, KeyPressedEventArgs args) { KeyPressed?.Invoke(this, args); }; }
public StateWalking(BoxingPlayer player, KeyPressed key) : base(player, "Walk") { this.key = key; player.currentHorizontalSpeed = player.direction * walkSpeed; canCombo = true; canCatch = true; }
public override void HandleKeyDownInput(int player_index, KeyPressed key) { if (key == KeyPressed.Defend && dodgeTryTimer <= 0) { dodgeTimer = dodgeThreshold; dodgeTryTimer = dodgeTryCooldown; } }
public void ChangeIndex(int playerIndex, KeyPressed key) { if (!ready) { if (key == KeyPressed.Left) selection = popup.GetColor(selection, true); else if (key == KeyPressed.Right) selection = popup.GetColor(selection, false); } }
public StateRunning(BoxingPlayer player, KeyPressed key) : base(player, "Run") { isStopping = false; this.key = key; player.currentHorizontalSpeed = runSpeed;//player.direction* runSpeed; canCombo = true; canCatch = true; runSpeed *= BoxingPlayer.Scale; }
public StateBowlerHatThrow(int itemIndex, BoxingPlayer player, KeyPressed key) : base(player, "BowlerThrow") { if (player.hasThrownBowlerHat) noHat = true; //ChangeState(new StateBowlerHatReThrow(itemIndex, player)); // Wait to recieve! holdTimer = MAX_HOLD_TIME; this.itemButton = key; }
public override void HandleKeyDownInput(int player_index, KeyPressed key) { if (key == itemButton) // pressing the item button? { if (shootCounter == 0 && (player.sprite.FrameIndex == 4 || player.sprite.FrameIndex == 5)) { player.soundEffects["RevolverShoot"].Play(.5f,0,0); // play the sound effect! shootCounter++; BoxingPlayer p = player.BoxingManager.GetPlayerInFront(player, player.position.Y - 7 * player.GetHeight / 9, player.direction); if (p != null && !(p.state is StateKnockedDown)) { p.beingComboedTimer = p.beingComboedCooldown; p.revolverHitCounter++; p.state.isHit(p, new StateRevolverHit(p), damage); /*if(p.state is StateRevolverHit) { StateRevolverHit s = (StateRevolverHit)p.state s.hitCounter = shootCounter; }*/ } } else if (shootCounter < 5 && (player.sprite.FrameIndex == 8 || player.sprite.FrameIndex == 9)) { player.sprite.FrameIndex = 5; shootCounter++; BoxingPlayer p = player.BoxingManager.GetPlayerInFront(player, player.position.Y - 2 * player.GetHeight / 3, player.direction); if (p != null && !(p.state is StateKnockedDown)) { player.soundEffects["RevolverShoot"].Play(.5f, 0, 0); // play the sound effect! p.state.isHit(player, new StateRevolverHit(p), damage); /*if(p.state is StateRevolverHit) { StateRevolverHit s = (StateRevolverHit)p.state s.hitCounter = shootCounter; }*/ // reset combo counter p.beingComboedTimer = p.beingComboedCooldown; p.revolverHitCounter++; Debug.WriteLine("Hit " + p.revolverHitCounter + " times!"); if (p.beingComboedTimer > 0 && p.revolverHitCounter >= 5) { p.state.ChangeState(new StateKnockedDown(p, player.direction, true)); //player.CurrentHealth -= damage; } } } } base.HandleKeyDownInput(player_index, key); }
// Use this for initialization void Start() { unitController = GetComponent<UnitController> (); rotateRightKeyCode = (KeyCode) System.Enum.Parse(typeof(KeyCode), RotateRightKey); rotateLeftKeyCode = (KeyCode) System.Enum.Parse(typeof(KeyCode), RotateLeftKey); rotateRight += RotateRight; rotateLeft += RotateLeft; placeBomb += PlaceBomb; }
public StateRevolverShoot(int itemIndex, BoxingPlayer player, KeyPressed key) : base(player, "RevolverShoot") { isAttack = false; player.input.OnKeyDown += HandleKeyDownInput; shootCounter = 0; this.itemButton = key; canCatch = true; }
// Handles input from first player. public void HandleInput(int playerIndex, KeyPressed key) { // If you select accept, tell the manager we're done. if (key == KeyPressed.Attack1 && menu.entries[menu.index] == "Accept") { manager.OnStateComplete("Settings"); } else { // let the menu handle it menu.ChangeIndex(playerIndex, key); } }
void OnKeyPressed(KeyPressed msg) { if (msg.Key == Keys.Space) { m_Controller.Constraint.TryJump = true; return; } Vector3 action; if (!m_ActionMap.TryGetValue(msg.Key, out action)) return; m_Controller.Constraint.TargetVelocity += m_Speed * action; }
public override void ChangeIndex(int playerIndex, KeyPressed key) { // When the up or down event is fired, move the index. if (key == KeyPressed.Left) { soundMenu.Play(1, .6f, 0); Rounds--; } else if (key == KeyPressed.Right) { soundMenu.Play(1, .6f, 0); Rounds++; } base.ChangeIndex(playerIndex, key); }
void OnKeyPressed(KeyPressed msg) { if (msg.Key == Keys.Space) { m_Physics.ApplyImpulse(Vector2.UnitY * m_JumpForce); } if (msg.Key == Keys.Right) ShootBullet(Vector2.UnitX); if (msg.Key == Keys.Left) ShootBullet(-Vector2.UnitX); if (msg.Key == Keys.Up) ShootBullet(Vector2.UnitY); if (msg.Key == Keys.Down) ShootBullet(-Vector2.UnitY); }
public void HandleInput(int player_index, KeyPressed key) { if (key == KeyPressed.Up) { if (loadouts[player_index] != null)// && loadouts[player_index].Index != 0) loadouts[player_index].Index--; } if (key == KeyPressed.Down) { if (loadouts[player_index] != null )//&& loadouts[player_index].Index != loadouts[player_index].num_entries - 1) loadouts[player_index].Index++; } if (key == KeyPressed.Right) { if (loadouts[player_index] != null && loadouts[player_index].Index == loadouts[player_index].num_entries - 1) ready[player_index] = 1; else if (loadouts[player_index] != null && loadouts[player_index].Index == 1) loadouts[player_index].ChangeDisplay(false); } if (key == KeyPressed.Left) { // player is active, and currently selecting the "items" entry. if (loadouts[player_index] != null && loadouts[player_index].Index == 1) loadouts[player_index].ChangeDisplay(true); } // Equip the item to the button they pressed if (key == KeyPressed.Attack1) { if (loadouts[player_index] != null && loadouts[player_index].Index == 1) loadouts[player_index].EquipItem(0); } if (key == KeyPressed.Attack2) { if (loadouts[player_index] != null && loadouts[player_index].Index == 1) loadouts[player_index].EquipItem(1); } if (key == KeyPressed.Attack3) { if (loadouts[player_index] != null && loadouts[player_index].Index == 1) loadouts[player_index].EquipItem(2); } if (key == KeyPressed.Attack4) { if (loadouts[player_index] != null && loadouts[player_index].Index == 1) loadouts[player_index].EquipItem(3); } }
public override void HandleKeyDownInput(int player_index, KeyPressed key) { if ( key == KeyPressed.Down) { ChangeState(new StateDuck(player)); } base.HandleKeyDownInput(player_index, key); }
/// <summary> /// Adds a key down to the hook. /// </summary> /// <param name="key">The key to be added.</param> /// <param name="callback">The function to be called when the key is pressed.</param> public static bool AddKeyDown(Keys key, KeyPressed callback) { KeyDown = null; if (!handledKeysDown.ContainsKey(key)) { handledKeysDown.Add(key, callback); return true; } else return false; }
/// <summary> /// AddKeyDown wrapper /// </summary> /// <param name="key">The key to be added.</param> /// <param name="callback">The function to be called when the key is pressed.</param> public static bool Add(Keys key, KeyPressed callback) { return AddKeyDown(key, callback); }
/// <summary> /// Adds a key up to the hook. /// </summary> /// <param name="key">The key to be added.</param> /// <param name="callback">The function to be called when the key is pressed.</param> public static bool AddKeyUp(Keys key, KeyPressed callback) { if (!handledKeysUp.ContainsKey(key)) { handledKeysUp.Add(key, callback); return true; } else return false; }
private void timer2_Tick(object sender, EventArgs e) { switch (lastKey) { /*case KeyPressed.Space: fallFigur.rotate(); break;*/ case KeyPressed.A: if (canLeft(fallFigur)) { fallFigur.LeftPoint = new Point(fallFigur.LeftPoint.X - width, fallFigur.LeftPoint.Y); pictureBox1.Invalidate(); } break; case KeyPressed.D: if (canRight(fallFigur)) { fallFigur.LeftPoint = new Point(fallFigur.LeftPoint.X + width, fallFigur.LeftPoint.Y); pictureBox1.Invalidate(); } break; case KeyPressed.S: timer1.Enabled=timer2.Enabled=false; while (canFall(fallFigur)) { fallFigur.stepFigure(); } liyPoints.AddRange(fallFigur.FillPoints); foreach (Point pn in fallFigur.FillPoints) { tetr[pn.X / width, pn.Y / width] = true; } checkLine(); cehckFail(); fallFigur = randomFigure(); pictureBox1.Invalidate(); timer1.Enabled = timer2.Enabled = true; lastKey = KeyPressed.None; break; } }
public virtual void HandleKeyDownInput(int player_index, KeyPressed key) { if (!player.isAirborn && key == KeyPressed.Jump) { player.isAirborn = true; player.position.Y -= 5; player.currentVerticalSpeed = -400; } }
public void HandleInput(int player_index, KeyPressed key) { if(loadTimer <= 0 && isActive) { for (int i = 0; i < 4; i++) { // Find the player if (player_index == i) { if (key == KeyPressed.Attack1) { // Are they joining? if (!playerAdded[i]) { soundMenuD.Play(); totalPlayers++; playerAdded[i] = true; // Enable input for the menu inputs[i].OnKeyRelease += menus[i].ChangeIndex; if (availableSelections.Count > 0) { menus[i].selection = availableSelections[0]; availableSelections.RemoveAt(0); } } else { // Are they readying or unreadying? if (!ready[i]) { soundMenuD.Play(); ready[i] = true; menus[i].ready = true; } else { soundMenuA.Play(); menus[i].ready = false; ready[i] = false; } } } } } } }
public bool IsKeyDown(KeyPressed key) { return StatePlayer.KeysDown.Contains(key); }
public bool isOneOfTheseDown(KeyPressed key1, KeyPressed key2, KeyPressed key3, KeyPressed key4) { return StatePlayer.IsKeyDown(key1) || StatePlayer.IsKeyDown(key2) || StatePlayer.IsKeyDown(key3) || StatePlayer.IsKeyDown(key4); }
public bool areKeysDown(KeyPressed key1, KeyPressed key2, KeyPressed key3) { return StatePlayer.IsKeyDown(key1) && StatePlayer.IsKeyDown(key2) && StatePlayer.IsKeyDown(key3); }
private void Form1_KeyDown(object sender, KeyEventArgs e) { switch (e.KeyCode) { case Keys.A: lastKey = KeyPressed.A; break; case Keys.D: lastKey = KeyPressed.D; break; case Keys.S: lastKey = KeyPressed.S; break; case Keys.Space: lastKey = KeyPressed.Space; fallFigur.rotate(); int countStep = 0; while (!canRight(fallFigur)) { countStep++; fallFigur.LeftPoint = new Point(fallFigur.LeftPoint.X - width,fallFigur.LeftPoint.Y); } if (countStep > 0) fallFigur.LeftPoint = new Point(fallFigur.LeftPoint.X + width, fallFigur.LeftPoint.Y); countStep = 0; while (!canLeft(fallFigur)) { countStep++; fallFigur.LeftPoint = new Point(fallFigur.LeftPoint.X + width,fallFigur.LeftPoint.Y); } if (countStep > 0) fallFigur.LeftPoint = new Point(fallFigur.LeftPoint.X - width, fallFigur.LeftPoint.Y); pictureBox1.Invalidate(); break; } }
protected override void OnKeyDown(System.Windows.Forms.KeyEventArgs e) { base.OnKeyDown(e); //--------------------------------------------------------------------------------- // Detect when the decimal point on the keypad, or the space bar is pressed //--------------------------------------------------------------------------------- switch (e.KeyCode.ToString().ToLower()) { case "decimal": meLastKeystroke = KeyPressed.NumberPadDecimal; break; case "space": meLastKeystroke = KeyPressed.SpaceBar; break; default: meLastKeystroke = KeyPressed.NothingSpecial; break; } }
public virtual void HandleKeyReleaseInput(int player_index, KeyPressed key) { }
private void Form1_KeyUp(object sender, KeyEventArgs e) { switch (e.KeyCode) { case Keys.A: lastKey = KeyPressed.None; break; case Keys.D: lastKey = KeyPressed.None; break; case Keys.S: lastKey = KeyPressed.None; break; case Keys.Space: lastKey = KeyPressed.None; break; } }