1
0
mirror of https://github.com/Artemis-RGB/Artemis synced 2025-12-13 05:48:35 +00:00

Input - Added basic input stuff

This commit is contained in:
SpoinkyNL 2020-11-22 00:01:55 +01:00
parent 0c8e200f53
commit 810db36191
16 changed files with 962 additions and 6 deletions

View File

@ -55,6 +55,7 @@
<s:Boolean x:Key="/Default/CodeInspection/NamespaceProvider/NamespaceFoldersToSkip/=rgb_002Enet/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/CodeInspection/NamespaceProvider/NamespaceFoldersToSkip/=services_005Ccolorquantizer/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/CodeInspection/NamespaceProvider/NamespaceFoldersToSkip/=services_005Ccolorquantizer_005Cinterfaces/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/CodeInspection/NamespaceProvider/NamespaceFoldersToSkip/=services_005Cinput/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/CodeInspection/NamespaceProvider/NamespaceFoldersToSkip/=services_005Cinterfaces/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/CodeInspection/NamespaceProvider/NamespaceFoldersToSkip/=services_005Cregistration/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/CodeInspection/NamespaceProvider/NamespaceFoldersToSkip/=services_005Cregistration_005Cinterfaces/@EntryIndexedValue">True</s:Boolean>

View File

@ -1,4 +1,5 @@
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq;
using Artemis.Core.DeviceProviders;
@ -22,6 +23,7 @@ namespace Artemis.Core
RgbDevice = rgbDevice;
DeviceProvider = deviceProvider;
Surface = surface;
InputIdentifiers = new List<ArtemisDeviceInputIdentifier>();
DeviceEntity = new DeviceEntity();
_leds = rgbDevice.Select(l => new ArtemisLed(l, this)).ToList().AsReadOnly();
@ -38,6 +40,7 @@ namespace Artemis.Core
RgbDevice = rgbDevice;
DeviceProvider = deviceProvider;
Surface = surface;
InputIdentifiers = new List<ArtemisDeviceInputIdentifier>();
DeviceEntity = deviceEntity;
_leds = rgbDevice.Select(l => new ArtemisLed(l, this)).ToList().AsReadOnly();
}
@ -84,6 +87,11 @@ namespace Artemis.Core
private set => SetAndNotify(ref _leds, value);
}
/// <summary>
/// Gets a list of input identifiers associated with this device
/// </summary>
public List<ArtemisDeviceInputIdentifier> InputIdentifiers { get; }
/// <summary>
/// Gets or sets the X-position of the device
/// </summary>
@ -174,6 +182,16 @@ namespace Artemis.Core
{
// Other properties are computed
DeviceEntity.DeviceIdentifier = RgbDevice.GetDeviceIdentifier();
DeviceEntity.InputIdentifier.Clear();
foreach (ArtemisDeviceInputIdentifier identifier in InputIdentifiers)
{
DeviceEntity.InputIdentifier.Add(new DeviceInputIdentifierEntity
{
InputProvider = identifier.InputProvider,
Identifier = identifier.Identifier
});
}
}
internal void ApplyToRgbDevice()
@ -186,6 +204,10 @@ namespace Artemis.Core
RgbDevice.Location = new Point(1, 1);
RgbDevice.Location = new Point(DeviceEntity.X, DeviceEntity.Y);
InputIdentifiers.Clear();
foreach (DeviceInputIdentifierEntity identifierEntity in DeviceEntity.InputIdentifier)
InputIdentifiers.Add(new ArtemisDeviceInputIdentifier(identifierEntity.InputProvider, identifierEntity.Identifier));
CalculateRenderProperties();
OnDeviceUpdated();
}

View File

@ -0,0 +1,31 @@
using Artemis.Core.Services;
namespace Artemis.Core
{
/// <summary>
/// Represents a device input identifier used by a specific <see cref="Services.InputProvider" /> to identify the device
/// </summary>
public class ArtemisDeviceInputIdentifier
{
/// <summary>
/// Creates a new instance of the <see cref="ArtemisDeviceInputIdentifier" /> class
/// </summary>
/// <param name="inputProvider">The full type and namespace of the <see cref="Services.InputProvider" /> this identifier is used by</param>
/// <param name="identifier">A value used to identify the device</param>
public ArtemisDeviceInputIdentifier(string inputProvider, object identifier)
{
InputProvider = inputProvider;
Identifier = identifier;
}
/// <summary>
/// Gets or sets the full type and namespace of the <see cref="Services.InputProvider" /> this identifier is used by
/// </summary>
public string InputProvider { get; set; }
/// <summary>
/// Gets or sets a value used to identify the device
/// </summary>
public object Identifier { get; set; }
}
}

View File

@ -0,0 +1,359 @@
namespace Artemis.Core.Services
{
/// <summary>Specifies the possible key values on a keyboard.</summary>
public enum InputKey
{
/// <summary>No key pressed.</summary>
None = 0,
/// <summary>The Cancel key.</summary>
Cancel = 1,
/// <summary>The Backspace key.</summary>
Back = 2,
/// <summary>The Tab key.</summary>
Tab = 3,
/// <summary>The Linefeed key.</summary>
LineFeed = 4,
/// <summary>The Clear key.</summary>
Clear = 5,
/// <summary>The Enter key.</summary>
Enter = 6,
/// <summary>The Return key.</summary>
Return = 6,
/// <summary>The Pause key.</summary>
Pause = 7,
/// <summary>The Caps Lock key.</summary>
CapsLock = 8,
/// <summary>The IME Hangul mode key.</summary>
HangulMode = 9,
/// <summary>The IME Junja mode key.</summary>
JunjaMode = 10, // 0x0000000A
/// <summary>The IME Final mode key.</summary>
FinalMode = 11, // 0x0000000B
/// <summary>The IME Hanja mode key.</summary>
HanjaMode = 12, // 0x0000000C
/// <summary>The ESC key.</summary>
Escape = 13, // 0x0000000D
/// <summary>The IME Convert key.</summary>
ImeConvert = 14, // 0x0000000E
/// <summary>The IME NonConvert key.</summary>
ImeNonConvert = 15, // 0x0000000F
/// <summary>The IME Accept key.</summary>
ImeAccept = 16, // 0x00000010
/// <summary>The IME Mode change request.</summary>
ImeModeChange = 17, // 0x00000011
/// <summary>The Spacebar key.</summary>
Space = 18, // 0x00000012
/// <summary>The Page Up key.</summary>
PageUp = 19, // 0x00000013
/// <summary>The Page Up key.</summary>
Prior = 19, // 0x00000013
/// <summary>The Page Down key.</summary>
Next = 20, // 0x00000014
/// <summary>The Page Down key.</summary>
PageDown = 20, // 0x00000014
/// <summary>The End key.</summary>
End = 21, // 0x00000015
/// <summary>The Home key.</summary>
Home = 22, // 0x00000016
/// <summary>The Left Arrow key.</summary>
Left = 23, // 0x00000017
/// <summary>The Up Arrow key.</summary>
Up = 24, // 0x00000018
/// <summary>The Right Arrow key.</summary>
Right = 25, // 0x00000019
/// <summary>The Down Arrow key.</summary>
Down = 26, // 0x0000001A
/// <summary>The Select key.</summary>
Select = 27, // 0x0000001B
/// <summary>The Print key.</summary>
Print = 28, // 0x0000001C
/// <summary>The Execute key.</summary>
Execute = 29, // 0x0000001D
/// <summary>The Print Screen key.</summary>
PrintScreen = 30, // 0x0000001E
/// <summary>The Insert key.</summary>
Insert = 31, // 0x0000001F
/// <summary>The Delete key.</summary>
Delete = 32, // 0x00000020
/// <summary>The Help key.</summary>
Help = 33, // 0x00000021
/// <summary>The 0 (zero) key.</summary>
D0 = 34, // 0x00000022
/// <summary>The 1 (one) key.</summary>
D1 = 35, // 0x00000023
/// <summary>The 2 key.</summary>
D2 = 36, // 0x00000024
/// <summary>The 3 key.</summary>
D3 = 37, // 0x00000025
/// <summary>The 4 key.</summary>
D4 = 38, // 0x00000026
/// <summary>The 5 key.</summary>
D5 = 39, // 0x00000027
/// <summary>The 6 key.</summary>
D6 = 40, // 0x00000028
/// <summary>The 7 key.</summary>
D7 = 41, // 0x00000029
/// <summary>The 8 key.</summary>
D8 = 42, // 0x0000002A
/// <summary>The 9 key.</summary>
D9 = 43, // 0x0000002B
/// <summary>The A key.</summary>
A = 44, // 0x0000002C
/// <summary>The B key.</summary>
B = 45, // 0x0000002D
/// <summary>The C key.</summary>
C = 46, // 0x0000002E
/// <summary>The D key.</summary>
D = 47, // 0x0000002F
/// <summary>The E key.</summary>
E = 48, // 0x00000030
/// <summary>The F key.</summary>
F = 49, // 0x00000031
/// <summary>The G key.</summary>
G = 50, // 0x00000032
/// <summary>The H key.</summary>
H = 51, // 0x00000033
/// <summary>The I key.</summary>
I = 52, // 0x00000034
/// <summary>The J key.</summary>
J = 53, // 0x00000035
/// <summary>The K key.</summary>
K = 54, // 0x00000036
/// <summary>The L key.</summary>
L = 55, // 0x00000037
/// <summary>The M key.</summary>
M = 56, // 0x00000038
/// <summary>The N key.</summary>
N = 57, // 0x00000039
/// <summary>The O key.</summary>
O = 58, // 0x0000003A
/// <summary>The P key.</summary>
P = 59, // 0x0000003B
/// <summary>The Q key.</summary>
Q = 60, // 0x0000003C
/// <summary>The R key.</summary>
R = 61, // 0x0000003D
/// <summary>The S key.</summary>
S = 62, // 0x0000003E
/// <summary>The T key.</summary>
T = 63, // 0x0000003F
/// <summary>The U key.</summary>
U = 64, // 0x00000040
/// <summary>The V key.</summary>
V = 65, // 0x00000041
/// <summary>The W key.</summary>
W = 66, // 0x00000042
/// <summary>The X key.</summary>
X = 67, // 0x00000043
/// <summary>The Y key.</summary>
Y = 68, // 0x00000044
/// <summary>The Z key.</summary>
Z = 69, // 0x00000045
/// <summary>The left Windows logo key (Microsoft Natural Keyboard).</summary>
LWin = 70, // 0x00000046
/// <summary>The right Windows logo key (Microsoft Natural Keyboard).</summary>
RWin = 71, // 0x00000047
/// <summary>The Application key (Microsoft Natural Keyboard). Also known as the Menu key, as it displays an application-specific context menu.</summary>
Apps = 72, // 0x00000048
/// <summary>The Computer Sleep key.</summary>
Sleep = 73, // 0x00000049
/// <summary>The 0 key on the numeric keypad.</summary>
NumPad0 = 74, // 0x0000004A
/// <summary>The 1 key on the numeric keypad.</summary>
NumPad1 = 75, // 0x0000004B
/// <summary>The 2 key on the numeric keypad.</summary>
NumPad2 = 76, // 0x0000004C
/// <summary>The 3 key on the numeric keypad.</summary>
NumPad3 = 77, // 0x0000004D
/// <summary>The 4 key on the numeric keypad.</summary>
NumPad4 = 78, // 0x0000004E
/// <summary>The 5 key on the numeric keypad.</summary>
NumPad5 = 79, // 0x0000004F
/// <summary>The 6 key on the numeric keypad.</summary>
NumPad6 = 80, // 0x00000050
/// <summary>The 7 key on the numeric keypad.</summary>
NumPad7 = 81, // 0x00000051
/// <summary>The 8 key on the numeric keypad.</summary>
NumPad8 = 82, // 0x00000052
/// <summary>The 9 key on the numeric keypad.</summary>
NumPad9 = 83, // 0x00000053
/// <summary>The Multiply key.</summary>
Multiply = 84, // 0x00000054
/// <summary>The Add key.</summary>
Add = 85, // 0x00000055
/// <summary>The Separator key.</summary>
Separator = 86, // 0x00000056
/// <summary>The Subtract key.</summary>
Subtract = 87, // 0x00000057
/// <summary>The Decimal key.</summary>
Decimal = 88, // 0x00000058
/// <summary>The Divide key.</summary>
Divide = 89, // 0x00000059
/// <summary>The F1 key.</summary>
F1 = 90, // 0x0000005A
/// <summary>The F2 key.</summary>
F2 = 91, // 0x0000005B
/// <summary>The F3 key.</summary>
F3 = 92, // 0x0000005C
/// <summary>The F4 key.</summary>
F4 = 93, // 0x0000005D
/// <summary>The F5 key.</summary>
F5 = 94, // 0x0000005E
/// <summary>The F6 key.</summary>
F6 = 95, // 0x0000005F
/// <summary>The F7 key.</summary>
F7 = 96, // 0x00000060
/// <summary>The F8 key.</summary>
F8 = 97, // 0x00000061
/// <summary>The F9 key.</summary>
F9 = 98, // 0x00000062
/// <summary>The F10 key.</summary>
F10 = 99, // 0x00000063
/// <summary>The F11 key.</summary>
F11 = 100, // 0x00000064
/// <summary>The F12 key.</summary>
F12 = 101, // 0x00000065
/// <summary>The F13 key.</summary>
F13 = 102, // 0x00000066
/// <summary>The F14 key.</summary>
F14 = 103, // 0x00000067
/// <summary>The F15 key.</summary>
F15 = 104, // 0x00000068
/// <summary>The F16 key.</summary>
F16 = 105, // 0x00000069
/// <summary>The F17 key.</summary>
F17 = 106, // 0x0000006A
/// <summary>The F18 key.</summary>
F18 = 107, // 0x0000006B
/// <summary>The F19 key.</summary>
F19 = 108, // 0x0000006C
/// <summary>The F20 key.</summary>
F20 = 109, // 0x0000006D
/// <summary>The F21 key.</summary>
F21 = 110, // 0x0000006E
/// <summary>The F22 key.</summary>
F22 = 111, // 0x0000006F
/// <summary>The F23 key.</summary>
F23 = 112, // 0x00000070
/// <summary>The F24 key.</summary>
F24 = 113, // 0x00000071
/// <summary>The Num Lock key.</summary>
NumLock = 114, // 0x00000072
/// <summary>The Scroll Lock key.</summary>
Scroll = 115, // 0x00000073
/// <summary>The left Shift key.</summary>
LeftShift = 116, // 0x00000074
/// <summary>The right Shift key.</summary>
RightShift = 117, // 0x00000075
/// <summary>The left CTRL key.</summary>
LeftCtrl = 118, // 0x00000076
/// <summary>The right CTRL key.</summary>
RightCtrl = 119, // 0x00000077
/// <summary>The left ALT key.</summary>
LeftAlt = 120, // 0x00000078
/// <summary>The right ALT key.</summary>
RightAlt = 121, // 0x00000079
/// <summary>The Browser Back key.</summary>
BrowserBack = 122, // 0x0000007A
/// <summary>The Browser Forward key.</summary>
BrowserForward = 123, // 0x0000007B
/// <summary>The Browser Refresh key.</summary>
BrowserRefresh = 124, // 0x0000007C
/// <summary>The Browser Stop key.</summary>
BrowserStop = 125, // 0x0000007D
/// <summary>The Browser Search key.</summary>
BrowserSearch = 126, // 0x0000007E
/// <summary>The Browser Favorites key.</summary>
BrowserFavorites = 127, // 0x0000007F
/// <summary>The Browser Home key.</summary>
BrowserHome = 128, // 0x00000080
/// <summary>The Volume Mute key.</summary>
VolumeMute = 129, // 0x00000081
/// <summary>The Volume Down key.</summary>
VolumeDown = 130, // 0x00000082
/// <summary>The Volume Up key.</summary>
VolumeUp = 131, // 0x00000083
/// <summary>The Media Next Track key.</summary>
MediaNextTrack = 132, // 0x00000084
/// <summary>The Media Previous Track key.</summary>
MediaPreviousTrack = 133, // 0x00000085
/// <summary>The Media Stop key.</summary>
MediaStop = 134, // 0x00000086
/// <summary>The Media Play Pause key.</summary>
MediaPlayPause = 135, // 0x00000087
/// <summary>The Launch Mail key.</summary>
LaunchMail = 136, // 0x00000088
/// <summary>The Select Media key.</summary>
SelectMedia = 137, // 0x00000089
/// <summary>The Launch Application1 key.</summary>
LaunchApplication1 = 138, // 0x0000008A
/// <summary>The Launch Application2 key.</summary>
LaunchApplication2 = 139, // 0x0000008B
/// <summary>The OEM Semicolon key.</summary>
OemSemicolon = 140, // 0x0000008C
/// <summary>The OEM Addition key.</summary>
OemPlus = 141, // 0x0000008D
/// <summary>The OEM Comma key.</summary>
OemComma = 142, // 0x0000008E
/// <summary>The OEM Minus key.</summary>
OemMinus = 143, // 0x0000008F
/// <summary>The OEM Period key.</summary>
OemPeriod = 144, // 0x00000091
/// <summary>The OEM Question key.</summary>
OemQuestion = 145, // 0x00000092
/// <summary>The OEM Tilde key.</summary>
OemTilde = 146, // 0x00000092
/// <summary>The ABNT_C1 (Brazilian) key.</summary>
AbntC1 = 147, // 0x00000093
/// <summary>The ABNT_C2 (Brazilian) key.</summary>
AbntC2 = 148, // 0x00000095
/// <summary>The OEM Open Brackets key.</summary>
OemOpenBrackets = 149, // 0x00000096
/// <summary>The OEM Pipe key.</summary>
OemPipe = 150, // 0x00000096
/// <summary>The OEM Close Brackets key.</summary>
OemCloseBrackets = 151, // 0x00000097
/// <summary>The OEM Quotes key.</summary>
OemQuotes = 152, // 0x00000098
/// <summary>The OEM Backslash key.</summary>
OemBackslash = 154, // 0x0000009A
/// <summary>A special key masking the real key being processed by an IME.</summary>
ImeProcessed = 155, // 0x0000009B
/// <summary>A special key masking the real key being processed as a system key.</summary>
System = 156, // 0x0000009C
/// <summary>The OEM ATTN key.</summary>
OemAttn = 157, // 0x0000009D
/// <summary>The OEM FINISH key.</summary>
OemFinish = 158, // 0x0000009E
/// <summary>The OEM COPY key.</summary>
OemCopy = 159, // 0x0000009F
/// <summary>The OEM AUTO key.</summary>
OemAuto = 160, // 0x000000A0
/// <summary>The OEM ENLW key.</summary>
OemEnlw = 161, // 0x000000A1
/// <summary>The OEM BACKTAB key.</summary>
OemBackTab = 162, // 0x000000A2
/// <summary>The ATTN key.</summary>
Attn = 163, // 0x000000A3
/// <summary>The CRSEL key.</summary>
CrSel = 164, // 0x000000A4
/// <summary>The EXSEL key.</summary>
ExSel = 165, // 0x000000A5
/// <summary>The ERASE EOF key.</summary>
EraseEof = 166, // 0x000000A6
/// <summary>The PLAY key.</summary>
Play = 167, // 0x000000A7
/// <summary>The ZOOM key.</summary>
Zoom = 168, // 0x000000A8
/// <summary>A constant reserved for future use.</summary>
NoName = 169, // 0x000000A9
/// <summary>The PA1 key.</summary>
Pa1 = 170, // 0x000000AA
/// <summary>The OEM Clear key.</summary>
OemClear = 171, // 0x000000AB
/// <summary>The key is used with another key to create a single combined character.</summary>
DeadCharProcessed = 172, // 0x000000AC,
/// <summary>The NumPad enter key</summary>
NumPadEnter,
}
}

View File

@ -0,0 +1,185 @@
using System.Collections.Generic;
using RGB.NET.Core;
namespace Artemis.Core.Services
{
internal static class InputKeyUtilities
{
internal static readonly Dictionary<InputKey, LedId> LedIdMap = new Dictionary<InputKey, LedId>()
{
{InputKey.None, LedId.Keyboard_Custom1},
{InputKey.Cancel, LedId.Keyboard_Custom2},
{InputKey.Back, LedId.Keyboard_Backspace},
{InputKey.Tab, LedId.Keyboard_Tab},
{InputKey.LineFeed, LedId.Keyboard_Custom3},
{InputKey.Clear, LedId.Keyboard_Custom4},
{InputKey.Enter, LedId.Keyboard_Enter},
{InputKey.Pause, LedId.Keyboard_PauseBreak},
{InputKey.CapsLock, LedId.Keyboard_CapsLock},
{InputKey.HangulMode, LedId.Keyboard_Custom4},
{InputKey.JunjaMode, LedId.Keyboard_Custom5},
{InputKey.FinalMode, LedId.Keyboard_Custom6},
{InputKey.HanjaMode, LedId.Keyboard_Custom7},
{InputKey.Escape, LedId.Keyboard_Escape},
{InputKey.ImeConvert, LedId.Keyboard_Custom8},
{InputKey.ImeNonConvert, LedId.Keyboard_Custom9},
{InputKey.ImeAccept, LedId.Keyboard_Custom10},
{InputKey.ImeModeChange, LedId.Keyboard_Custom11},
{InputKey.Space, LedId.Keyboard_Space},
{InputKey.PageUp, LedId.Keyboard_PageUp},
{InputKey.PageDown, LedId.Keyboard_PageDown},
{InputKey.End, LedId.Keyboard_End},
{InputKey.Home, LedId.Keyboard_Home},
{InputKey.Left, LedId.Keyboard_ArrowLeft},
{InputKey.Up, LedId.Keyboard_ArrowUp},
{InputKey.Right, LedId.Keyboard_ArrowRight},
{InputKey.Down, LedId.Keyboard_ArrowDown},
{InputKey.Select, LedId.Keyboard_Custom12},
{InputKey.Print, LedId.Keyboard_Custom13},
{InputKey.Execute, LedId.Keyboard_Custom14},
{InputKey.PrintScreen, LedId.Keyboard_PrintScreen},
{InputKey.Insert, LedId.Keyboard_Insert},
{InputKey.Delete, LedId.Keyboard_Delete},
{InputKey.Help, LedId.Keyboard_Custom15},
{InputKey.D0, LedId.Keyboard_0},
{InputKey.D1, LedId.Keyboard_1},
{InputKey.D2, LedId.Keyboard_2},
{InputKey.D3, LedId.Keyboard_3},
{InputKey.D4, LedId.Keyboard_4},
{InputKey.D5, LedId.Keyboard_5},
{InputKey.D6, LedId.Keyboard_6},
{InputKey.D7, LedId.Keyboard_7},
{InputKey.D8, LedId.Keyboard_8},
{InputKey.D9, LedId.Keyboard_9},
{InputKey.A, LedId.Keyboard_A},
{InputKey.B, LedId.Keyboard_B},
{InputKey.C, LedId.Keyboard_C},
{InputKey.D, LedId.Keyboard_D},
{InputKey.E, LedId.Keyboard_E},
{InputKey.F, LedId.Keyboard_F},
{InputKey.G, LedId.Keyboard_G},
{InputKey.H, LedId.Keyboard_H},
{InputKey.I, LedId.Keyboard_I},
{InputKey.J, LedId.Keyboard_J},
{InputKey.K, LedId.Keyboard_K},
{InputKey.L, LedId.Keyboard_L},
{InputKey.M, LedId.Keyboard_M},
{InputKey.N, LedId.Keyboard_N},
{InputKey.O, LedId.Keyboard_O},
{InputKey.P, LedId.Keyboard_P},
{InputKey.Q, LedId.Keyboard_Q},
{InputKey.R, LedId.Keyboard_R},
{InputKey.S, LedId.Keyboard_S},
{InputKey.T, LedId.Keyboard_T},
{InputKey.U, LedId.Keyboard_U},
{InputKey.V, LedId.Keyboard_V},
{InputKey.W, LedId.Keyboard_W},
{InputKey.X, LedId.Keyboard_X},
{InputKey.Y, LedId.Keyboard_Y},
{InputKey.Z, LedId.Keyboard_Z},
{InputKey.LWin, LedId.Keyboard_LeftGui},
{InputKey.RWin, LedId.Keyboard_RightGui},
{InputKey.Apps, LedId.Keyboard_Application},
{InputKey.Sleep, LedId.Keyboard_Custom16},
{InputKey.NumPad0, LedId.Keyboard_Num0},
{InputKey.NumPad1, LedId.Keyboard_Num1},
{InputKey.NumPad2, LedId.Keyboard_Num2},
{InputKey.NumPad3, LedId.Keyboard_Num3},
{InputKey.NumPad4, LedId.Keyboard_Num4},
{InputKey.NumPad5, LedId.Keyboard_Num5},
{InputKey.NumPad6, LedId.Keyboard_Num6},
{InputKey.NumPad7, LedId.Keyboard_Num7},
{InputKey.NumPad8, LedId.Keyboard_Num8},
{InputKey.NumPad9, LedId.Keyboard_Num9},
{InputKey.Multiply, LedId.Keyboard_NumAsterisk},
{InputKey.Add, LedId.Keyboard_NumPlus},
{InputKey.Separator, LedId.Keyboard_NumEnter}, // unverified
{InputKey.Subtract, LedId.Keyboard_NumMinus},
{InputKey.Decimal, LedId.Keyboard_NumPeriodAndDelete},
{InputKey.Divide, LedId.Keyboard_NumSlash},
{InputKey.F1, LedId.Keyboard_F1},
{InputKey.F2, LedId.Keyboard_F2},
{InputKey.F3, LedId.Keyboard_F3},
{InputKey.F4, LedId.Keyboard_F4},
{InputKey.F5, LedId.Keyboard_F5},
{InputKey.F6, LedId.Keyboard_F6},
{InputKey.F7, LedId.Keyboard_F7},
{InputKey.F8, LedId.Keyboard_F8},
{InputKey.F9, LedId.Keyboard_F9},
{InputKey.F10, LedId.Keyboard_F10},
{InputKey.F11, LedId.Keyboard_F11},
{InputKey.F12, LedId.Keyboard_F12},
{InputKey.F13, LedId.Keyboard_Custom17},
{InputKey.F14, LedId.Keyboard_Custom18},
{InputKey.F15, LedId.Keyboard_Custom19},
{InputKey.F16, LedId.Keyboard_Custom20},
{InputKey.F17, LedId.Keyboard_Custom21},
{InputKey.F18, LedId.Keyboard_Custom22},
{InputKey.F19, LedId.Keyboard_Custom23},
{InputKey.F20, LedId.Keyboard_Custom24},
{InputKey.F21, LedId.Keyboard_Custom25},
{InputKey.F22, LedId.Keyboard_Custom26},
{InputKey.F23, LedId.Keyboard_Custom27},
{InputKey.F24, LedId.Keyboard_Custom28},
{InputKey.NumLock, LedId.Keyboard_NumLock},
{InputKey.Scroll, LedId.Keyboard_ScrollLock},
{InputKey.LeftShift, LedId.Keyboard_LeftShift},
{InputKey.RightShift, LedId.Keyboard_RightShift},
{InputKey.LeftCtrl, LedId.Keyboard_LeftCtrl},
{InputKey.RightCtrl, LedId.Keyboard_RightCtrl},
{InputKey.LeftAlt, LedId.Keyboard_LeftAlt},
{InputKey.RightAlt, LedId.Keyboard_RightAlt},
{InputKey.BrowserBack, LedId.Keyboard_Custom29},
{InputKey.BrowserForward, LedId.Keyboard_Custom30},
{InputKey.BrowserRefresh, LedId.Keyboard_Custom31},
{InputKey.BrowserStop, LedId.Keyboard_Custom32},
{InputKey.BrowserSearch, LedId.Keyboard_Custom33},
{InputKey.BrowserFavorites, LedId.Keyboard_Custom34},
{InputKey.BrowserHome, LedId.Keyboard_Custom35},
{InputKey.VolumeMute, LedId.Keyboard_MediaMute},
{InputKey.VolumeDown, LedId.Keyboard_MediaVolumeDown},
{InputKey.VolumeUp, LedId.Keyboard_MediaVolumeUp},
{InputKey.MediaNextTrack, LedId.Keyboard_MediaNextTrack},
{InputKey.MediaPreviousTrack, LedId.Keyboard_MediaPreviousTrack},
{InputKey.MediaStop, LedId.Keyboard_MediaStop},
{InputKey.MediaPlayPause, LedId.Keyboard_MediaPlay},
{InputKey.LaunchMail, LedId.Keyboard_Custom36},
{InputKey.SelectMedia, LedId.Keyboard_Custom37},
{InputKey.LaunchApplication1, LedId.Keyboard_Custom38},
{InputKey.LaunchApplication2, LedId.Keyboard_Custom39},
{InputKey.OemSemicolon, LedId.Keyboard_SemicolonAndColon},
{InputKey.OemPlus, LedId.Keyboard_EqualsAndPlus},
{InputKey.OemMinus, LedId.Keyboard_MinusAndUnderscore},
{InputKey.OemComma, LedId.Keyboard_CommaAndLessThan},
{InputKey.OemPeriod, LedId.Keyboard_PeriodAndBiggerThan},
{InputKey.OemQuestion, LedId.Keyboard_SlashAndQuestionMark},
{InputKey.OemTilde, LedId.Keyboard_GraveAccentAndTilde},
{InputKey.AbntC1, LedId.Keyboard_Custom40},
{InputKey.AbntC2, LedId.Keyboard_Custom41},
{InputKey.OemOpenBrackets, LedId.Keyboard_BracketLeft},
{InputKey.OemPipe, LedId.Keyboard_Backslash},
{InputKey.OemCloseBrackets, LedId.Keyboard_BracketRight},
{InputKey.OemQuotes, LedId.Keyboard_ApostropheAndDoubleQuote},
{InputKey.OemBackslash, LedId.Keyboard_Custom42}, // unverified
{InputKey.ImeProcessed, LedId.Keyboard_Custom43},
{InputKey.System, LedId.Keyboard_Custom44},
{InputKey.OemAttn, LedId.Keyboard_Custom45},
{InputKey.OemFinish, LedId.Keyboard_Custom46},
{InputKey.OemCopy, LedId.Keyboard_Custom47},
{InputKey.OemAuto, LedId.Keyboard_Custom48},
{InputKey.OemEnlw, LedId.Keyboard_Custom49},
{InputKey.OemBackTab, LedId.Keyboard_Custom50},
{InputKey.Attn, LedId.Keyboard_Custom51},
{InputKey.CrSel, LedId.Keyboard_Custom52},
{InputKey.ExSel, LedId.Keyboard_Custom53},
{InputKey.EraseEof, LedId.Keyboard_Custom54},
{InputKey.Play, LedId.Keyboard_MediaPlay},
{InputKey.Zoom, LedId.Keyboard_Custom55},
{InputKey.NoName, LedId.Keyboard_Custom56},
{InputKey.Pa1, LedId.Keyboard_Custom57},
{InputKey.OemClear, LedId.Keyboard_Custom58},
{InputKey.DeadCharProcessed, LedId.Keyboard_Custom59},
{InputKey.NumPadEnter, LedId.Keyboard_NumEnter},
};
}
}

View File

@ -0,0 +1,49 @@
using System;
namespace Artemis.Core.Services
{
/// <summary>
/// Represents an interface for an input provider that provides and implementation for sending and receiving device
/// input
/// </summary>
public abstract class InputProvider : IDisposable
{
/// <summary>
/// Occurs when the input provided has received keyboard data
/// </summary>
public event EventHandler<InputProviderKeyboardEventArgs>? KeyboardDataReceived;
/// <summary>
/// Invokes the <see cref="KeyboardDataReceived" /> event
/// </summary>
protected virtual void OnKeyboardDataReceived(InputProviderKeyboardEventArgs e)
{
KeyboardDataReceived?.Invoke(this, e);
}
#region IDisposable
/// <summary>
/// Releases the unmanaged resources used by the object and optionally releases the managed resources.
/// </summary>
/// <param name="disposing">
/// <see langword="true" /> to release both managed and unmanaged resources;
/// <see langword="false" /> to release only unmanaged resources.
/// </param>
protected virtual void Dispose(bool disposing)
{
if (disposing)
{
}
}
/// <inheritdoc />
public void Dispose()
{
Dispose(true);
GC.SuppressFinalize(this);
}
#endregion
}
}

View File

@ -0,0 +1,37 @@
using System;
namespace Artemis.Core.Services
{
/// <summary>
/// Contains data for input provider keyboard events
/// </summary>
public class InputProviderKeyboardEventArgs : EventArgs
{
/// <summary>
/// </summary>
/// <param name="device">The device that triggered the event</param>
/// <param name="key">The key that triggered the event</param>
/// <param name="isDown">Whether the key is pressed down</param>
public InputProviderKeyboardEventArgs(ArtemisDevice device, InputKey key, bool isDown)
{
Device = device;
Key = key;
IsDown = isDown;
}
/// <summary>
/// Gets the device that triggered the event
/// </summary>
public ArtemisDevice Device { get; }
/// <summary>
/// Gets the key that triggered the event
/// </summary>
public InputKey Key { get; }
/// <summary>
/// Gets whether the key is pressed down
/// </summary>
public bool IsDown { get; }
}
}

View File

@ -0,0 +1,59 @@
using System.Collections.Generic;
using RGB.NET.Core;
using Serilog;
namespace Artemis.Core.Services
{
internal class InputService : IInputService
{
private readonly ILogger _logger;
private readonly List<InputProvider> _inputProviders;
public InputService(ILogger logger)
{
_logger = logger;
_inputProviders = new List<InputProvider>();
}
public void AddInputProvider(InputProvider inputProvider)
{
_inputProviders.Add(inputProvider);
inputProvider.KeyboardDataReceived += InputProviderOnKeyboardDataReceived;
}
public void RemoveInputProvider(InputProvider inputProvider)
{
if (!_inputProviders.Contains(inputProvider))
return;
inputProvider.KeyboardDataReceived -= InputProviderOnKeyboardDataReceived;
}
private void InputProviderOnKeyboardDataReceived(object? sender, InputProviderKeyboardEventArgs e)
{
if (!(sender is InputProvider inputProvider))
return;
bool foundLedId = InputKeyUtilities.LedIdMap.TryGetValue(e.Key, out LedId ledId);
_logger.Verbose("Received keyboard data: LED ID: {ledId}, key: {key}, is down: {isDown}, device: {device} ", ledId, e.Key, e.IsDown, e.Device);
}
}
/// <summary>
/// A service that allows you to interact with keyboard and mice input events
/// </summary>
public interface IInputService : IArtemisService
{
/// <summary>
/// Adds an input provided
/// </summary>
/// <param name="inputProvider">The input provider the add</param>
void AddInputProvider(InputProvider inputProvider);
/// <summary>
/// Removes an input provided
/// </summary>
/// <param name="inputProvider">The input provider the remove</param>
void RemoveInputProvider(InputProvider inputProvider);
}
}

View File

@ -245,7 +245,7 @@ namespace Artemis.Core.Services
// Load the entity and fall back on creating a new one
Plugin plugin = new Plugin(pluginInfo, directory, _pluginRepository.GetPluginByGuid(pluginInfo.Guid));
OnPluginLoading(new PluginEventArgs(plugin));
// Locate the main assembly entry
string? mainFile = plugin.ResolveRelativePath(plugin.Info.Main);
if (!File.Exists(mainFile))
@ -289,6 +289,8 @@ namespace Artemis.Core.Services
// Create the Ninject child kernel and load the module
plugin.Kernel = new ChildKernel(_kernel, new PluginModule(plugin));
OnPluginEnabling(new PluginEventArgs(plugin));
plugin.SetEnabled(true);
// Get the Plugin feature from the main assembly and if there is only one, instantiate it

View File

@ -1,12 +1,27 @@
namespace Artemis.Storage.Entities.Surface
using System.Collections.Generic;
namespace Artemis.Storage.Entities.Surface
{
public class DeviceEntity
{
public DeviceEntity()
{
InputIdentifier = new List<DeviceInputIdentifierEntity>();
}
public string DeviceIdentifier { get; set; }
public double X { get; set; }
public double Y { get; set; }
public double Rotation { get; set; }
public double Scale { get; set; }
public int ZIndex { get; set; }
public List<DeviceInputIdentifierEntity> InputIdentifier { get; set; }
}
public class DeviceInputIdentifierEntity
{
public string InputProvider { get; set; }
public object Identifier { get; set; }
}
}

View File

@ -142,6 +142,7 @@
<PackageReference Include="Microsoft.Xaml.Behaviors.Wpf" Version="1.1.19" />
<PackageReference Include="Ninject" Version="3.3.4" />
<PackageReference Include="Ninject.Extensions.Conventions" Version="3.3.0" />
<PackageReference Include="RawInput.Sharp" Version="0.0.3" />
<PackageReference Include="Serilog" Version="2.9.0" />
<PackageReference Include="SkiaSharp.Views.WPF" Version="2.80.2" />
<PackageReference Include="Stylet" Version="1.3.4" />

View File

@ -14,6 +14,7 @@ using Artemis.Core.Ninject;
using Artemis.Core.Services;
using Artemis.UI.Ninject;
using Artemis.UI.Screens;
using Artemis.UI.Services;
using Artemis.UI.Shared;
using Artemis.UI.Shared.Services;
using Artemis.UI.Stylet;
@ -42,6 +43,7 @@ namespace Artemis.UI
ILogger logger = Kernel.Get<ILogger>();
IViewManager viewManager = Kernel.Get<IViewManager>();
IRegistrationService registrationService = Kernel.Get<IRegistrationService>();
StartupArguments = Args.ToList();
CreateDataDirectory(logger);
@ -70,7 +72,7 @@ namespace Artemis.UI
{
if (StartupArguments.Contains("--autorun"))
{
logger.Information("Sleeping for 15 seconds on auto run to allow applications like iCUE and LGS to start");
logger.Information("Sleeping for 15 seconds on auto run to allow vendor applications required for SDKs to start");
await Task.Delay(TimeSpan.FromSeconds(15));
}
@ -83,6 +85,8 @@ namespace Artemis.UI
throw;
}
});
registrationService.RegisterInputProvider();
}
protected override void ConfigureIoC(IKernel kernel)

View File

@ -0,0 +1,141 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Windows.Forms;
using System.Windows.Input;
using Artemis.Core;
using Artemis.Core.Services;
using Linearstar.Windows.RawInput;
using Linearstar.Windows.RawInput.Native;
using RGB.NET.Core;
namespace Artemis.UI.InputProviders
{
public class NativeWindowInputProvider : InputProvider
{
private const int WM_INPUT = 0x00FF;
private readonly ISurfaceService _surfaceService;
private List<ArtemisDevice> _keyboards;
private DateTime _lastMouseUpdate;
private List<ArtemisDevice> _mice;
private SpongeWindow _sponge;
public NativeWindowInputProvider(ISurfaceService surfaceService)
{
_surfaceService = surfaceService;
_sponge = new SpongeWindow();
_sponge.WndProcCalled += SpongeOnWndProcCalled;
RawInputDevice.RegisterDevice(HidUsageAndPage.Keyboard, RawInputDeviceFlags.ExInputSink | RawInputDeviceFlags.NoLegacy, _sponge.Handle);
RawInputDevice.RegisterDevice(HidUsageAndPage.Mouse, RawInputDeviceFlags.InputSink, _sponge.Handle);
_surfaceService.ActiveSurfaceConfigurationSelected += SurfaceConfigurationChanged;
_surfaceService.SurfaceConfigurationUpdated += SurfaceConfigurationChanged;
GetDevices(surfaceService.ActiveSurface);
}
#region IDisposable
/// <inheritdoc />
protected override void Dispose(bool disposing)
{
if (disposing)
{
_sponge?.DestroyHandle();
_sponge = null;
_surfaceService.ActiveSurfaceConfigurationSelected -= SurfaceConfigurationChanged;
_surfaceService.SurfaceConfigurationUpdated -= SurfaceConfigurationChanged;
}
base.Dispose(disposing);
}
#endregion
private void SurfaceConfigurationChanged(object sender, SurfaceConfigurationEventArgs e)
{
GetDevices(e.Surface);
}
private void GetDevices(ArtemisSurface surface)
{
_keyboards = surface.Devices.Where(d => d.RgbDevice.DeviceInfo.DeviceType == RGBDeviceType.Keyboard).ToList();
_mice = surface.Devices.Where(d => d.RgbDevice.DeviceInfo.DeviceType == RGBDeviceType.Mouse).ToList();
}
private void SpongeOnWndProcCalled(object sender, Message message)
{
if (message.Msg != WM_INPUT)
return;
RawInputData data = RawInputData.FromHandle(message.LParam);
switch (data)
{
case RawInputMouseData mouse:
HandleMouseData(mouse);
break;
case RawInputKeyboardData keyboard:
HandleKeyboardData(keyboard);
break;
}
}
private void HandleKeyboardData(RawInputKeyboardData data)
{
// Get the keyboard that submitted the data
ArtemisDevice match = _keyboards?.FirstOrDefault();
if (match == null)
return;
InputKey key = (InputKey) KeyInterop.KeyFromVirtualKey(data.Keyboard.VirutalKey);
// Debug.WriteLine($"VK: {key} ({data.Keyboard.VirutalKey}), Flags: {data.Keyboard.Flags}, Scan code: {data.Keyboard.ScanCode}");
// Sometimes we get double hits and they resolve to None, ignore those
if (key == InputKey.None)
return;
// Right alt triggers LeftCtrl with a different scan code for some reason, ignore those
if (key == InputKey.LeftCtrl && data.Keyboard.ScanCode == 56)
return;
// Duplicate keys with different positions can be identified by the LeftKey flag (even though its set of the key that's physically on the right)
if (data.Keyboard.Flags == RawKeyboardFlags.LeftKey || data.Keyboard.Flags == (RawKeyboardFlags.LeftKey | RawKeyboardFlags.Up))
{
if (key == InputKey.Enter)
key = InputKey.NumPadEnter;
if (key == InputKey.LeftCtrl)
key = InputKey.RightCtrl;
if (key == InputKey.LeftAlt)
key = InputKey.RightAlt;
}
if (key == InputKey.LeftShift && data.Keyboard.ScanCode == 54)
key = InputKey.RightShift;
bool isDown = data.Keyboard.Flags != RawKeyboardFlags.Up &&
data.Keyboard.Flags != (RawKeyboardFlags.Up | RawKeyboardFlags.LeftKey) &&
data.Keyboard.Flags != (RawKeyboardFlags.Up | RawKeyboardFlags.RightKey);
OnKeyboardDataReceived(new InputProviderKeyboardEventArgs(match, key, isDown));
}
private void HandleMouseData(RawInputMouseData data)
{
// Only handle mouse movement 25 times per second
if (data.Mouse.Buttons == RawMouseButtonFlags.None)
if (DateTime.Now - _lastMouseUpdate < TimeSpan.FromMilliseconds(40))
return;
_lastMouseUpdate = DateTime.Now;
// Get the keyboard that submitted the data
ArtemisDevice match = _mice?.FirstOrDefault();
if (match == null)
return;
}
}
}

View File

@ -0,0 +1,26 @@
using System;
using System.Windows.Forms;
namespace Artemis.UI.InputProviders
{
public sealed class SpongeWindow : NativeWindow
{
public SpongeWindow()
{
CreateHandle(new CreateParams());
}
public event EventHandler<Message> WndProcCalled;
protected override void WndProc(ref Message m)
{
OnWndProcCalled(m);
base.WndProc(ref m);
}
private void OnWndProcCalled(Message e)
{
WndProcCalled?.Invoke(this, e);
}
}
}

View File

@ -3,6 +3,7 @@ using Artemis.Core;
using Artemis.Core.Services;
using Artemis.UI.DefaultTypes.DataModel.Display;
using Artemis.UI.DefaultTypes.DataModel.Input;
using Artemis.UI.InputProviders;
using Artemis.UI.Ninject;
using Artemis.UI.PropertyInput;
using Artemis.UI.Services.Interfaces;
@ -15,18 +16,26 @@ namespace Artemis.UI.Services
private readonly IDataModelUIService _dataModelUIService;
private readonly IProfileEditorService _profileEditorService;
private readonly IPluginManagementService _pluginManagementService;
private readonly ISurfaceService _surfaceService;
private readonly IInputService _inputService;
private bool _registeredBuiltInDataModelDisplays;
private bool _registeredBuiltInDataModelInputs;
private bool _registeredBuiltInPropertyEditors;
public RegistrationService(IDataModelUIService dataModelUIService, IProfileEditorService profileEditorService, IPluginManagementService pluginManagementService)
public RegistrationService(IDataModelUIService dataModelUIService,
IProfileEditorService profileEditorService,
IPluginManagementService pluginManagementService,
ISurfaceService surfaceService,
IInputService inputService)
{
_dataModelUIService = dataModelUIService;
_profileEditorService = profileEditorService;
_pluginManagementService = pluginManagementService;
_surfaceService = surfaceService;
_inputService = inputService;
LoadPluginModules();
pluginManagementService.PluginLoaded += PluginServiceOnPluginLoaded;
pluginManagementService.PluginEnabling += PluginServiceOnPluginEnabling;
}
public void RegisterBuiltInDataModelDisplays()
@ -74,7 +83,12 @@ namespace Artemis.UI.Services
_registeredBuiltInPropertyEditors = true;
}
private void PluginServiceOnPluginLoaded(object sender, PluginEventArgs e)
public void RegisterInputProvider()
{
_inputService.AddInputProvider(new NativeWindowInputProvider(_surfaceService));
}
private void PluginServiceOnPluginEnabling(object sender, PluginEventArgs e)
{
e.Plugin.Kernel.Load(new[] {new PluginUIModule(e.Plugin)});
}
@ -91,5 +105,6 @@ namespace Artemis.UI.Services
void RegisterBuiltInDataModelDisplays();
void RegisterBuiltInDataModelInputs();
void RegisterBuiltInPropertyEditors();
void RegisterInputProvider();
}
}

View File

@ -80,6 +80,15 @@
"Ninject.Extensions.Factory": "3.3.2"
}
},
"RawInput.Sharp": {
"type": "Direct",
"requested": "[0.0.3, )",
"resolved": "0.0.3",
"contentHash": "X5EuJYuU0RWzOnA68cHmLEJ4czhgu0EsQj3o5RtYSdTNnTnXo/zVNAXQWPWbBXgoLsws1WTsT567yX0HKjS4aA==",
"dependencies": {
"NETStandard.Library": "1.6.1"
}
},
"Serilog": {
"type": "Direct",
"requested": "[2.9.0, )",