A game framework written with osu! in mind.
at master 1.2 kB view raw
1// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence. 2// See the LICENCE file in the repository root for full licence text. 3 4using System.Collections.Generic; 5using osu.Framework.Extensions.TypeExtensions; 6using osu.Framework.Input.States; 7using osuTK.Input; 8 9namespace osu.Framework.Input.Events 10{ 11 /// <summary> 12 /// Events of a keyboard key. 13 /// </summary> 14 public abstract class KeyboardEvent : UIEvent 15 { 16 public readonly Key Key; 17 18 /// <summary> 19 /// Whether a specific key is pressed. 20 /// </summary> 21 public bool IsPressed(Key key) => CurrentState.Keyboard.Keys.IsPressed(key); 22 23 /// <summary> 24 /// Whether any key is pressed. 25 /// </summary> 26 public bool HasAnyKeyPressed => CurrentState.Keyboard.Keys.HasAnyButtonPressed; 27 28 /// <summary> 29 /// List of currently pressed keys. 30 /// </summary> 31 public IEnumerable<Key> PressedKeys => CurrentState.Keyboard.Keys; 32 33 protected KeyboardEvent(InputState state, Key key) 34 : base(state) 35 { 36 Key = key; 37 } 38 39 public override string ToString() => $"{GetType().ReadableName()}({Key})"; 40 } 41}