A game framework written with osu! in mind.
at master 1.3 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 System.Linq; 6using osu.Framework.Graphics; 7using osu.Framework.Input.Events; 8using osu.Framework.Input.States; 9using osuTK.Input; 10 11namespace osu.Framework.Input 12{ 13 /// <summary> 14 /// Manages state events for a single key. 15 /// </summary> 16 public class KeyEventManager : ButtonEventManager<Key> 17 { 18 public KeyEventManager(Key key) 19 : base(key) 20 { 21 } 22 23 public void HandleRepeat(InputState state) 24 { 25 // Only drawables that can still handle input should handle the repeat 26 var drawables = ButtonDownInputQueue.Intersect(InputQueue).Where(t => t.IsAlive && t.IsPresent); 27 28 PropagateButtonEvent(drawables, new KeyDownEvent(state, Button, true)); 29 } 30 31 protected override Drawable HandleButtonDown(InputState state, List<Drawable> targets) => PropagateButtonEvent(targets, new KeyDownEvent(state, Button)); 32 33 protected override void HandleButtonUp(InputState state, List<Drawable> targets) 34 { 35 if (targets == null) 36 return; 37 38 PropagateButtonEvent(targets, new KeyUpEvent(state, Button)); 39 } 40 } 41}