-
-
Notifications
You must be signed in to change notification settings - Fork 444
Proposal for a keyboard, mouse, and human input API #16
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
d0430b0
A start, but that's it for today
Perksey f094fe5
Continue work on input proposal
Perksey 7d1b76c
Syntax highlighting
Perksey 3b386fe
Update Proposal - Input.md
Perksey 673c1a2
Update Proposal - Input.md
Perksey 02d1337
Update Proposal - Input.md
Perksey f0f292e
Add buttons
Perksey 5eea9d7
Update Proposal - Input.md
Perksey 4f33a0d
Update Proposal - Input.md
Perksey 5dc8ac1
Update Proposal - Input.md
Perksey 55b9ea8
Update Proposal - Input.md
Perksey 44d5a4b
Update Proposal - Input.md
Perksey File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,391 @@ | ||
| # Summary | ||
| Proposal API for Input via keyboards, mice, and controllers. | ||
|
|
||
| # Contributors | ||
| - Dylan Perks, Ultz Limited | ||
| - Aaron Pearson, Ultz Limited | ||
| - Vassalware, Silk.NET Contributors | ||
|
|
||
| # Current Status | ||
| - [x] Proposed | ||
| - [ ] Discussed with API Review Board (ARB) | ||
| - [ ] Approved | ||
| - [ ] Implemented | ||
|
|
||
| # Design Decisions | ||
| - Vibration has been excluded from this proposal, as we'd like to come up with a complete API for HD Rumble etc. | ||
| - I've decided to use interfaces for nearly everything, so that the implementation has more control. | ||
| - All modifications of states (i.e. functions) will go within the interface, whereas structs are used for read-only data. | ||
| - **IMPLEMENTATION DETAIL/REQUIREMENT:** In implementations, once an IJoystick, IGamepad, or other IInputDevice object has been created, **it must not be destroyed until its IInputContext is disposed**. This is to preserve event bindings. | ||
| - ButtonDown/Up and KeyDown/Up events (and similar) all fire once, when the key is first pushed down or up. I intend to champion a few extension packages to support more use cases, but I've kept this API pretty barebones. | ||
|
|
||
| # Proposed API | ||
| ## Interfaces | ||
|
|
||
| ### IJoystick | ||
| ```cs | ||
| public interface IJoystick : IInputDevice | ||
| { | ||
| IReadOnlyCollection<Axis> Axes { get; } | ||
| IReadOnlyCollection<Button> Buttons { get; } | ||
| IReadOnlyCollection<Hat> Hats { get; } | ||
| Deadzone Deadzone { get; set; } | ||
| event Action<IJoystick, Button> ButtonDown; | ||
| event Action<IJoystick, Button> ButtonUp; | ||
| event Action<IJoystick, Axis> AxisMoved; | ||
| event Action<IJoystick, Hat> HatMoved; | ||
| } | ||
| ``` | ||
|
|
||
| ### IGamepad | ||
| ```cs | ||
| public interface IGamepad : IInputDevice | ||
Perksey marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| { | ||
| IReadOnlyCollection<Button> Buttons { get; } | ||
| IReadOnlyCollection<Thumbstick> Thumbsticks { get; } | ||
| IReadOnlyCollection<Trigger> Triggers { get; } | ||
| Deadzone Deadzone { get; set; } | ||
| event Action<IGamepad, Button> ButtonDown; | ||
| event Action<IGamepad, Button> ButtonUp; | ||
| event Action<IGamepad, Thumbstick> ThumbstickMoved; | ||
| event Action<IGamepad, Thumbstick> TriggerMoved; | ||
| } | ||
| ``` | ||
|
|
||
| ### IKeyboard | ||
| ```cs | ||
| public interface IKeyboard : IInputDevice | ||
| { | ||
| IReadOnlyCollection<Key> SupportedKeys { get; } | ||
| bool IsKeyPressed(Key key); | ||
| bool IsKeyPressed(uint scancode); | ||
| event Action<IKeyboard, Key> KeyDown; | ||
| event Action<IKeyboard, Key> KeyUp; | ||
| } | ||
| ``` | ||
|
|
||
| ### IMouse | ||
| ```cs | ||
| public interface IMouse : IInputDevice | ||
| { | ||
| IReadOnlyCollection<MouseButton> SupportedButtons { get; } | ||
| IReadOnlyCollection<ScrollWheel> ScrollWheels { get; } | ||
| bool IsButtonPressed(MouseButton btn); | ||
| event Action<IMouse, MouseButton> MouseDown; | ||
| event Action<IMouse, MouseButton> MouseUp; | ||
| event Action<IMouse, ScrollWheel> Scroll; | ||
| } | ||
| ``` | ||
|
|
||
| ### IInputDevice | ||
| ```cs | ||
| public interface IInputDevice | ||
Perksey marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| { | ||
| string Name { get; } | ||
| int Index { get; } | ||
| bool IsConnected { get; } | ||
| event Action<IInputDevice, bool> ConnectionChanged; | ||
| } | ||
| ``` | ||
|
|
||
| ### IInputContext | ||
| ```cs | ||
| public interface IInputContext : IDisposable | ||
| { | ||
| IntPtr Handle { get; } | ||
| IReadOnlyCollection<IGamepad> Gamepads { get; } | ||
| IReadOnlyCollection<IJoystick> Joysticks { get; } | ||
| IReadOnlyCollection<IKeyboard> Keyboards { get; } | ||
| IReadOnlyCollection<IMouse> Mice { get; } | ||
| IReadOnlyCollection<IInputDevice> OtherDevices { get; } | ||
| } | ||
| ``` | ||
|
|
||
| ### IInputPlatform\<T\> | ||
| ```cs | ||
| public interface IInputPlatform | ||
| { | ||
| bool IsApplicable(IWindow window); | ||
| IInputContext GetInput(IWindow window); | ||
| } | ||
| ``` | ||
|
|
||
| ## Classes | ||
|
|
||
| ### InputWindowExtensions | ||
| ```cs | ||
| public static class InputWindowExtensions | ||
| { | ||
| public static void RegisterInputPlatform(IInputPlatform platform); | ||
| public static void DeregisterInputPlatform(IInputPlatform platform); | ||
| public static IInputContext GetInput(this IWindow window); | ||
| } | ||
| ``` | ||
|
|
||
| ## Structs | ||
| ### ScrollWheel | ||
| ```cs | ||
| public struct ScrollWheel | ||
| { | ||
| public float X { get; } | ||
| public float Y { get; } | ||
| } | ||
| ``` | ||
|
|
||
| ### Button | ||
| ```cs | ||
| public struct Button | ||
| { | ||
| public ButtonName Name { get; } | ||
| public int Index { get; } | ||
| public bool Pressed { get; } | ||
| } | ||
| ``` | ||
|
|
||
| ### Axis | ||
| ```cs | ||
| public struct Axis | ||
| { | ||
| public int Index { get; } | ||
| public float Position { get; } | ||
| } | ||
| ``` | ||
|
|
||
| ### Thumbstick | ||
| ```cs | ||
| public struct Thumbstick | ||
| { | ||
| public int Index { get; } | ||
| public float Position { get; } | ||
| public float Direction { get; } | ||
| } | ||
| ``` | ||
|
|
||
| ### Trigger | ||
| ```cs | ||
| public struct Trigger | ||
| { | ||
| public int Index { get; } | ||
| public float Position { get; } | ||
| } | ||
| ``` | ||
|
|
||
| ### Hat | ||
| ```cs | ||
| public struct Hat | ||
| { | ||
| public int Index { get; } | ||
| public Position2D Position { get; } | ||
| } | ||
| ``` | ||
|
|
||
| ### Deadzone | ||
| ```cs | ||
| public struct Deadzone | ||
| { | ||
| public float Value { get; } | ||
| public DeadzoneMethod Method { get; } | ||
| } | ||
| ``` | ||
|
|
||
| ## Enums | ||
| ### Position2D | ||
| ```cs | ||
| [Flags] // flags so we can support top left and top right etc (Up | Left, Up | Right) | ||
| public enum Position2D | ||
| { | ||
| Up, | ||
| Down, | ||
| Left, | ||
| Right | ||
| } | ||
| ``` | ||
|
|
||
| ### DeadzoneMethod | ||
| ```cs | ||
| public enum DeadzoneMethod | ||
| { | ||
| // y = x except where |x| is between 0 and d (the deadzone value) | ||
| Traditional, | ||
| // y = (1 - d)x + (d * sgn(x)) | ||
| AdaptiveGradient | ||
| } | ||
| ``` | ||
|
|
||
| ### ButtonName | ||
| ```cs | ||
| public enum ButtonName | ||
| { | ||
| A, | ||
| B, | ||
| X, | ||
| Y, | ||
| Back, | ||
| Home, | ||
| DPadUp, | ||
| DPadDown, | ||
| DPadLeft, | ||
| DPadRight, | ||
| LeftBumper, | ||
| LeftStick, | ||
| LeftTrigger, | ||
| RightBumper, | ||
| RightStick, | ||
| RightTrigger, | ||
| Start | ||
| } | ||
| ``` | ||
|
|
||
| ### Key | ||
| ```cs | ||
| public enum Key | ||
| { | ||
| Unknown = 0, | ||
| ShiftLeft, | ||
| LShift = ShiftLeft, | ||
| ShiftRight, | ||
| RShift = ShiftRight, | ||
| ControlLeft, | ||
| LControl = ControlLeft, | ||
| ControlRight, | ||
| RControl = ControlRight, | ||
| AltLeft, | ||
| LAlt = AltLeft, | ||
| AltRight, | ||
| RAlt = AltRight, | ||
| WinLeft, | ||
| LWin = WinLeft, | ||
| WinRight, | ||
| RWin = WinRight, | ||
| Menu, | ||
| F1, | ||
| F2, | ||
| F3, | ||
| F4, | ||
| F5, | ||
| F6, | ||
| F7, | ||
| F8, | ||
| F9, | ||
| F10, | ||
| F11, | ||
| F12, | ||
| F13, | ||
| F14, | ||
| F15, | ||
| F16, | ||
| F17, | ||
| F18, | ||
| F19, | ||
| F20, | ||
| F21, | ||
| F22, | ||
| F23, | ||
| F24, | ||
| F25, | ||
| F26, | ||
| F27, | ||
| F28, | ||
| F29, | ||
| F30, | ||
| F31, | ||
| F32, | ||
| F33, | ||
| F34, | ||
| F35, | ||
| Up, | ||
| Down, | ||
| Left, | ||
| Right, | ||
| Enter, | ||
| Escape, | ||
| Space, | ||
| Tab, | ||
| BackSpace, | ||
| Back = BackSpace, | ||
| Insert, | ||
| Delete, | ||
| PageUp, | ||
| PageDown, | ||
| Home, | ||
| End, | ||
| CapsLock, | ||
| ScrollLock, | ||
| PrintScreen, | ||
| Pause, | ||
| NumLock, | ||
| Clear, | ||
| Sleep, | ||
| Keypad0, | ||
| Keypad1, | ||
| Keypad2, | ||
| Keypad3, | ||
| Keypad4, | ||
| Keypad5, | ||
| Keypad6, | ||
| Keypad7, | ||
| Keypad8, | ||
| Keypad9, | ||
| KeypadDivide, | ||
| KeypadMultiply, | ||
| KeypadSubtract, | ||
| KeypadMinus = KeypadSubtract, | ||
| KeypadAdd, | ||
| KeypadPlus = KeypadAdd, | ||
| KeypadDecimal, | ||
| KeypadPeriod = KeypadDecimal, | ||
| KeypadEnter, | ||
| A, | ||
| B, | ||
| C, | ||
| D, | ||
| E, | ||
| F, | ||
| G, | ||
| H, | ||
| I, | ||
| J, | ||
| K, | ||
| L, | ||
| M, | ||
| N, | ||
| O, | ||
| P, | ||
| Q, | ||
| R, | ||
| S, | ||
| T, | ||
| U, | ||
| V, | ||
| W, | ||
| X, | ||
| Y, | ||
| Z, | ||
| Number0, | ||
| Number1, | ||
| Number2, | ||
| Number3, | ||
| Number4, | ||
| Number5, | ||
| Number6, | ||
| Number7, | ||
| Number8, | ||
| Number9, | ||
| Tilde, | ||
| Grave = Tilde, | ||
| Minus, | ||
| Plus, | ||
| BracketLeft, | ||
| LBracket = BracketLeft, | ||
| BracketRight, | ||
| RBracket = BracketRight, | ||
| Semicolon, | ||
| Quote, | ||
| Comma, | ||
| Period, | ||
| Slash, | ||
| BackSlash, | ||
| NonUSBackSlash, | ||
| LastKey | ||
| } | ||
| ``` | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.