| | 1 | | // Copyright (c) 2020-2022 dotBunny Inc. |
| | 2 | | // dotBunny licenses this file to you under the BSL-1.0 license. |
| | 3 | | // See the LICENSE file in the project root for more information. |
| | 4 | |
|
| | 5 | |
|
| | 6 | | namespace GDX.Developer.ConsoleCommands |
| | 7 | | { |
| | 8 | | #if UNITY_2022_2_OR_NEWER |
| | 9 | | public class InputKeyPressConsoleCommand : ConsoleCommandBase |
| | 10 | | { |
| | 11 | | InputProxy.KeyCode m_KeyCode; |
| | 12 | |
|
| | 13 | | /// <inheritdoc /> |
| | 14 | | public override bool Evaluate(float deltaTime) |
| 0 | 15 | | { |
| 0 | 16 | | InputProxy.KeyPress(m_KeyCode); |
| 0 | 17 | | return true; |
| 0 | 18 | | } |
| | 19 | |
|
| | 20 | | /// <inheritdoc /> |
| | 21 | | public override Console.ConsoleAccessLevel GetAccessLevel() |
| 0 | 22 | | { |
| 0 | 23 | | return Console.ConsoleAccessLevel.Developer; |
| 0 | 24 | | } |
| | 25 | |
|
| | 26 | | /// <inheritdoc /> |
| | 27 | | public override string GetKeyword() |
| 7 | 28 | | { |
| 7 | 29 | | return "input.keypress"; |
| 7 | 30 | | } |
| | 31 | |
|
| | 32 | | /// <inheritdoc /> |
| | 33 | | public override string GetHelpUsage() |
| 0 | 34 | | { |
| 0 | 35 | | return "input.keypress <name>"; |
| 0 | 36 | | } |
| | 37 | |
|
| | 38 | | /// <inheritdoc /> |
| | 39 | | public override string GetHelpMessage() |
| 0 | 40 | | { |
| 0 | 41 | | return |
| | 42 | | "Synthesize the down and up event for a designated keyboard key. See https://learn.microsoft.com/en-us/w |
| 0 | 43 | | } |
| | 44 | |
|
| | 45 | | /// <inheritdoc /> |
| | 46 | | public override ConsoleCommandBase GetInstance(string context) |
| 0 | 47 | | { |
| 0 | 48 | | InputKeyPressConsoleCommand command = |
| | 49 | | new InputKeyPressConsoleCommand { m_KeyCode = InputProxy.GetKeyCode(context) }; |
| 0 | 50 | | if (command.m_KeyCode != InputProxy.KeyCode.Invalid) |
| 0 | 51 | | { |
| 0 | 52 | | return command; |
| | 53 | | } |
| | 54 | |
|
| 0 | 55 | | UnityEngine.Debug.LogWarning($"Unable to parse key from '{context}'."); |
| 0 | 56 | | return null; |
| 0 | 57 | | } |
| | 58 | | } |
| | 59 | | #endif // UNITY_2022_2_OR_NEWER |
| | 60 | | } |