A game framework written with osu! in mind.
at master 4.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 osu.Framework.Input.Handlers; 6using osu.Framework.Input.StateChanges; 7using osu.Framework.Platform; 8using osuTK.Input; 9using UIKit; 10 11namespace osu.Framework.iOS.Input 12{ 13 public class IOSRawKeyboardHandler : InputHandler 14 { 15 internal bool KeyboardActive = true; 16 public override bool IsActive => KeyboardActive; 17 18 public override bool Initialize(GameHost host) 19 { 20 if (!(UIApplication.SharedApplication is GameUIApplication game)) 21 return false; 22 23 game.KeyEvent += (keyCode, isDown) => 24 { 25 if (IsActive && keyMap.ContainsKey(keyCode)) 26 PendingInputs.Enqueue(new KeyboardKeyInput(keyMap[keyCode], isDown)); 27 }; 28 29 return true; 30 } 31 32 private readonly Dictionary<int, Key> keyMap = new Dictionary<int, Key> 33 { 34 { 4, Key.A }, 35 { 5, Key.B }, 36 { 6, Key.C }, 37 { 7, Key.D }, 38 { 8, Key.E }, 39 { 9, Key.F }, 40 { 10, Key.G }, 41 { 11, Key.H }, 42 { 12, Key.I }, 43 { 13, Key.J }, 44 { 14, Key.K }, 45 { 15, Key.L }, 46 { 16, Key.M }, 47 { 17, Key.N }, 48 { 18, Key.O }, 49 { 19, Key.P }, 50 { 20, Key.Q }, 51 { 21, Key.R }, 52 { 22, Key.S }, 53 { 23, Key.T }, 54 { 24, Key.U }, 55 { 25, Key.V }, 56 { 26, Key.W }, 57 { 27, Key.X }, 58 { 28, Key.Y }, 59 { 29, Key.Z }, 60 { 30, Key.Number1 }, 61 { 31, Key.Number2 }, 62 { 32, Key.Number3 }, 63 { 33, Key.Number4 }, 64 { 34, Key.Number5 }, 65 { 35, Key.Number6 }, 66 { 36, Key.Number7 }, 67 { 37, Key.Number8 }, 68 { 38, Key.Number9 }, 69 { 39, Key.Number0 }, 70 { 40, Key.Enter }, 71 { 41, Key.Escape }, 72 { 42, Key.BackSpace }, 73 { 43, Key.Tab }, 74 { 44, Key.Space }, 75 { 45, Key.Minus }, 76 { 46, Key.Plus }, 77 { 47, Key.BracketLeft }, 78 { 48, Key.BracketRight }, 79 { 49, Key.BackSlash }, 80 { 51, Key.Semicolon }, 81 { 52, Key.Quote }, 82 { 53, Key.Grave }, 83 { 54, Key.Comma }, 84 { 55, Key.Period }, 85 { 56, Key.Slash }, 86 { 57, Key.CapsLock }, 87 { 58, Key.F1 }, 88 { 59, Key.F2 }, 89 { 60, Key.F3 }, 90 { 61, Key.F4 }, 91 { 62, Key.F5 }, 92 { 63, Key.F6 }, 93 { 64, Key.F7 }, 94 { 65, Key.F8 }, 95 { 66, Key.F9 }, 96 { 67, Key.F10 }, 97 { 68, Key.F11 }, 98 { 69, Key.F12 }, 99 { 74, Key.Home }, 100 { 75, Key.PageUp }, 101 { 76, Key.Delete }, 102 { 77, Key.End }, 103 { 78, Key.PageDown }, 104 { 79, Key.Right }, 105 { 80, Key.Left }, 106 { 81, Key.Down }, 107 { 82, Key.Up }, 108 { 83, Key.NumLock }, 109 { 84, Key.KeypadDivide }, 110 { 85, Key.KeypadMultiply }, 111 { 86, Key.KeypadMinus }, 112 { 87, Key.KeypadPlus }, 113 { 89, Key.Keypad1 }, 114 { 90, Key.Keypad2 }, 115 { 91, Key.Keypad3 }, 116 { 92, Key.Keypad4 }, 117 { 93, Key.Keypad5 }, 118 { 94, Key.Keypad6 }, 119 { 95, Key.Keypad7 }, 120 { 96, Key.Keypad8 }, 121 { 97, Key.Keypad9 }, 122 { 98, Key.Keypad0 }, 123 { 99, Key.KeypadDecimal }, 124 { 101, Key.Menu }, 125 { 104, Key.PrintScreen }, 126 { 105, Key.ScrollLock }, 127 { 106, Key.Pause }, 128 { 117, Key.Insert }, 129 { 224, Key.ControlLeft }, 130 { 225, Key.ShiftLeft }, 131 { 226, Key.AltLeft }, 132 { 227, Key.WinLeft }, 133 { 228, Key.ControlRight }, 134 { 229, Key.ShiftRight }, 135 { 230, Key.AltRight }, 136 { 231, Key.WinRight } 137 }; 138 } 139}