mirror of
https://github.com/Artemis-RGB/Artemis
synced 2025-12-13 05:48:35 +00:00
Input - Added mouse support
Input - Added device identification
This commit is contained in:
parent
810db36191
commit
84918f2d5b
@ -56,6 +56,9 @@
|
||||
<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_005Cinput_005Cenums/@EntryIndexedValue">True</s:Boolean>
|
||||
<s:Boolean x:Key="/Default/CodeInspection/NamespaceProvider/NamespaceFoldersToSkip/=services_005Cinput_005Cevents/@EntryIndexedValue">True</s:Boolean>
|
||||
<s:Boolean x:Key="/Default/CodeInspection/NamespaceProvider/NamespaceFoldersToSkip/=services_005Cinput_005Cinterfaces/@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>
|
||||
|
||||
@ -0,0 +1,23 @@
|
||||
namespace Artemis.Core.Services
|
||||
{
|
||||
/// <summary>
|
||||
/// Represents a device that provides input to the <see cref="IInputService" />
|
||||
/// </summary>
|
||||
public enum InputFallbackDeviceType
|
||||
{
|
||||
/// <summary>
|
||||
/// None
|
||||
/// </summary>
|
||||
None,
|
||||
|
||||
/// <summary>
|
||||
/// A keyboard
|
||||
/// </summary>
|
||||
Keyboard,
|
||||
|
||||
/// <summary>
|
||||
/// A mouse
|
||||
/// </summary>
|
||||
Mouse
|
||||
}
|
||||
}
|
||||
@ -1,359 +1,537 @@
|
||||
namespace Artemis.Core.Services
|
||||
{
|
||||
/// <summary>Specifies the possible key values on a keyboard.</summary>
|
||||
public enum InputKey
|
||||
public enum KeyboardKey
|
||||
{
|
||||
/// <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>
|
||||
|
||||
/// <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,
|
||||
NumPadEnter
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,26 @@
|
||||
using System;
|
||||
|
||||
namespace Artemis.Core.Services
|
||||
{
|
||||
/// <summary>
|
||||
/// Specifies the set of modifier keys.
|
||||
/// </summary>
|
||||
[Flags]
|
||||
public enum KeyboardModifierKeys
|
||||
{
|
||||
/// <summary>No modifiers are pressed.</summary>
|
||||
None = 0,
|
||||
|
||||
/// <summary>The ALT key.</summary>
|
||||
Alt = 1,
|
||||
|
||||
/// <summary>The CTRL key.</summary>
|
||||
Control = 2,
|
||||
|
||||
/// <summary>The SHIFT key.</summary>
|
||||
Shift = 4,
|
||||
|
||||
/// <summary>The Windows logo key.</summary>
|
||||
Windows = 8
|
||||
}
|
||||
}
|
||||
33
src/Artemis.Core/Services/Input/Enums/MouseButton.cs
Normal file
33
src/Artemis.Core/Services/Input/Enums/MouseButton.cs
Normal file
@ -0,0 +1,33 @@
|
||||
namespace Artemis.Core.Services
|
||||
{
|
||||
/// <summary>
|
||||
/// Specifies the buttons on a mouse
|
||||
/// </summary>
|
||||
public enum MouseButton
|
||||
{
|
||||
/// <summary>
|
||||
/// The left mouse button
|
||||
/// </summary>
|
||||
Left,
|
||||
|
||||
/// <summary>
|
||||
/// The middle mouse button
|
||||
/// </summary>
|
||||
Middle,
|
||||
|
||||
/// <summary>
|
||||
/// The right mouse button
|
||||
/// </summary>
|
||||
Right,
|
||||
|
||||
/// <summary>
|
||||
/// Extra mouse button 4 (backwards)
|
||||
/// </summary>
|
||||
Button4,
|
||||
|
||||
/// <summary>
|
||||
/// Extra mouse button 5 (forwards)
|
||||
/// </summary>
|
||||
Button5
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,14 @@
|
||||
namespace Artemis.Core.Services
|
||||
{
|
||||
/// <summary>
|
||||
/// Specifies mouse scrolling directions
|
||||
/// </summary>
|
||||
public enum MouseScrollDirection
|
||||
{
|
||||
/// <summary>A vertical scroll direction</summary>
|
||||
Vertical,
|
||||
|
||||
/// <summary>A horizontal scroll direction</summary>
|
||||
Horizontal
|
||||
}
|
||||
}
|
||||
@ -3,7 +3,7 @@
|
||||
namespace Artemis.Core.Services
|
||||
{
|
||||
/// <summary>
|
||||
/// Contains data for input provider keyboard events
|
||||
/// Contains data for input provider keyboard events
|
||||
/// </summary>
|
||||
public class InputProviderKeyboardEventArgs : EventArgs
|
||||
{
|
||||
@ -12,7 +12,7 @@ namespace Artemis.Core.Services
|
||||
/// <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)
|
||||
public InputProviderKeyboardEventArgs(ArtemisDevice? device, KeyboardKey key, bool isDown)
|
||||
{
|
||||
Device = device;
|
||||
Key = key;
|
||||
@ -22,12 +22,12 @@ namespace Artemis.Core.Services
|
||||
/// <summary>
|
||||
/// Gets the device that triggered the event
|
||||
/// </summary>
|
||||
public ArtemisDevice Device { get; }
|
||||
public ArtemisDevice? Device { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets the key that triggered the event
|
||||
/// </summary>
|
||||
public InputKey Key { get; }
|
||||
public KeyboardKey Key { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets whether the key is pressed down
|
||||
@ -0,0 +1,37 @@
|
||||
using System;
|
||||
|
||||
namespace Artemis.Core.Services
|
||||
{
|
||||
/// <summary>
|
||||
/// Contains data for input provider mouse button events
|
||||
/// </summary>
|
||||
public class InputProviderMouseButtonEventArgs : EventArgs
|
||||
{
|
||||
/// <summary>
|
||||
/// </summary>
|
||||
/// <param name="device">The device that triggered the event</param>
|
||||
/// <param name="button">The button that triggered the event</param>
|
||||
/// <param name="isDown">Whether the button is pressed down</param>
|
||||
public InputProviderMouseButtonEventArgs(ArtemisDevice? device, MouseButton button, bool isDown)
|
||||
{
|
||||
Device = device;
|
||||
Button = button;
|
||||
IsDown = isDown;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the device that triggered the event
|
||||
/// </summary>
|
||||
public ArtemisDevice? Device { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets the button that triggered the event
|
||||
/// </summary>
|
||||
public MouseButton Button { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets whether the button is pressed down
|
||||
/// </summary>
|
||||
public bool IsDown { get; }
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,51 @@
|
||||
using System;
|
||||
|
||||
namespace Artemis.Core.Services
|
||||
{
|
||||
/// <summary>
|
||||
/// Contains data for input provider mouse movement events
|
||||
/// </summary>
|
||||
public class InputProviderMouseMoveEventArgs : EventArgs
|
||||
{
|
||||
/// <summary>
|
||||
/// </summary>
|
||||
/// <param name="device">The device that triggered the event</param>
|
||||
/// <param name="cursorX">The X position of the mouse cursor (not necessarily tied to the specific device)</param>
|
||||
/// <param name="cursorY">The Y position of the mouse cursor (not necessarily tied to the specific device)</param>
|
||||
/// <param name="deltaX">The movement delta in the horizontal direction</param>
|
||||
/// <param name="deltaY">The movement delta in the vertical direction</param>
|
||||
public InputProviderMouseMoveEventArgs(ArtemisDevice? device, int cursorX, int cursorY, int deltaX, int deltaY)
|
||||
{
|
||||
Device = device;
|
||||
CursorX = cursorX;
|
||||
CursorY = cursorY;
|
||||
DeltaX = deltaX;
|
||||
DeltaY = deltaY;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the device that triggered the event
|
||||
/// </summary>
|
||||
public ArtemisDevice? Device { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets the X position of the mouse cursor (not necessarily tied to the specific device)
|
||||
/// </summary>
|
||||
public int CursorX { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets the Y position of the mouse cursor (not necessarily tied to the specific device)
|
||||
/// </summary>
|
||||
public int CursorY { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets the movement delta in the horizontal direction
|
||||
/// </summary>
|
||||
public int DeltaX { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets the movement delta in the vertical direction
|
||||
/// </summary>
|
||||
public int DeltaY { get; }
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,37 @@
|
||||
using System;
|
||||
|
||||
namespace Artemis.Core.Services
|
||||
{
|
||||
/// <summary>
|
||||
/// Contains data for input provider mouse button events
|
||||
/// </summary>
|
||||
public class InputProviderMouseScrollEventArgs : EventArgs
|
||||
{
|
||||
/// <summary>
|
||||
/// </summary>
|
||||
/// <param name="device">The device that triggered the event</param>
|
||||
/// <param name="direction">The direction in which was scrolled</param>
|
||||
/// <param name="delta">The scroll delta (can positive or negative)</param>
|
||||
public InputProviderMouseScrollEventArgs(ArtemisDevice? device, MouseScrollDirection direction, int delta)
|
||||
{
|
||||
Device = device;
|
||||
Direction = direction;
|
||||
Delta = delta;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the device that triggered the event
|
||||
/// </summary>
|
||||
public ArtemisDevice? Device { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets the direction in which was scrolled
|
||||
/// </summary>
|
||||
public MouseScrollDirection Direction { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets the scroll delta (can positive or negative)
|
||||
/// </summary>
|
||||
public int Delta { get; }
|
||||
}
|
||||
}
|
||||
54
src/Artemis.Core/Services/Input/Events/KeyboardEventArgs.cs
Normal file
54
src/Artemis.Core/Services/Input/Events/KeyboardEventArgs.cs
Normal file
@ -0,0 +1,54 @@
|
||||
using System;
|
||||
|
||||
namespace Artemis.Core.Services
|
||||
{
|
||||
/// <summary>
|
||||
/// Contains data for keyboard input events
|
||||
/// </summary>
|
||||
public class KeyboardEventArgs : EventArgs
|
||||
{
|
||||
internal KeyboardEventArgs(ArtemisDevice? device, ArtemisLed? led, KeyboardKey key, KeyboardModifierKeys modifiers)
|
||||
{
|
||||
Device = device;
|
||||
Led = led;
|
||||
Key = key;
|
||||
Modifiers = modifiers;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the device that triggered the event
|
||||
/// </summary>
|
||||
public ArtemisDevice? Device { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets the LED that corresponds to the pressed key
|
||||
/// </summary>
|
||||
public ArtemisLed? Led { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets the key that triggered the event
|
||||
/// </summary>
|
||||
public KeyboardKey Key { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets the modifiers that are pressed
|
||||
/// </summary>
|
||||
public KeyboardModifierKeys Modifiers { get; }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Contains data for keyboard input events
|
||||
/// </summary>
|
||||
public class KeyboardKeyUpDownEventArgs : KeyboardEventArgs
|
||||
{
|
||||
internal KeyboardKeyUpDownEventArgs(ArtemisDevice? device, ArtemisLed? led, KeyboardKey key, KeyboardModifierKeys modifiers, bool isDown) : base(device, led, key, modifiers)
|
||||
{
|
||||
IsDown = isDown;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Whether the key is being pressed down, if <see langword="false"/> the key is being released
|
||||
/// </summary>
|
||||
public bool IsDown { get; set; }
|
||||
}
|
||||
}
|
||||
@ -5,181 +5,190 @@ namespace Artemis.Core.Services
|
||||
{
|
||||
internal static class InputKeyUtilities
|
||||
{
|
||||
internal static readonly Dictionary<InputKey, LedId> LedIdMap = new Dictionary<InputKey, LedId>()
|
||||
internal static readonly Dictionary<KeyboardKey, LedId> KeyboardKeyLedIdMap = new Dictionary<KeyboardKey, 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},
|
||||
{KeyboardKey.None, LedId.Keyboard_Custom1},
|
||||
{KeyboardKey.Cancel, LedId.Keyboard_Custom2},
|
||||
{KeyboardKey.Back, LedId.Keyboard_Backspace},
|
||||
{KeyboardKey.Tab, LedId.Keyboard_Tab},
|
||||
{KeyboardKey.LineFeed, LedId.Keyboard_Custom3},
|
||||
{KeyboardKey.Clear, LedId.Keyboard_Custom4},
|
||||
{KeyboardKey.Enter, LedId.Keyboard_Enter},
|
||||
{KeyboardKey.Pause, LedId.Keyboard_PauseBreak},
|
||||
{KeyboardKey.CapsLock, LedId.Keyboard_CapsLock},
|
||||
{KeyboardKey.HangulMode, LedId.Keyboard_Custom4},
|
||||
{KeyboardKey.JunjaMode, LedId.Keyboard_Custom5},
|
||||
{KeyboardKey.FinalMode, LedId.Keyboard_Custom6},
|
||||
{KeyboardKey.HanjaMode, LedId.Keyboard_Custom7},
|
||||
{KeyboardKey.Escape, LedId.Keyboard_Escape},
|
||||
{KeyboardKey.ImeConvert, LedId.Keyboard_Custom8},
|
||||
{KeyboardKey.ImeNonConvert, LedId.Keyboard_Custom9},
|
||||
{KeyboardKey.ImeAccept, LedId.Keyboard_Custom10},
|
||||
{KeyboardKey.ImeModeChange, LedId.Keyboard_Custom11},
|
||||
{KeyboardKey.Space, LedId.Keyboard_Space},
|
||||
{KeyboardKey.PageUp, LedId.Keyboard_PageUp},
|
||||
{KeyboardKey.PageDown, LedId.Keyboard_PageDown},
|
||||
{KeyboardKey.End, LedId.Keyboard_End},
|
||||
{KeyboardKey.Home, LedId.Keyboard_Home},
|
||||
{KeyboardKey.Left, LedId.Keyboard_ArrowLeft},
|
||||
{KeyboardKey.Up, LedId.Keyboard_ArrowUp},
|
||||
{KeyboardKey.Right, LedId.Keyboard_ArrowRight},
|
||||
{KeyboardKey.Down, LedId.Keyboard_ArrowDown},
|
||||
{KeyboardKey.Select, LedId.Keyboard_Custom12},
|
||||
{KeyboardKey.Print, LedId.Keyboard_Custom13},
|
||||
{KeyboardKey.Execute, LedId.Keyboard_Custom14},
|
||||
{KeyboardKey.PrintScreen, LedId.Keyboard_PrintScreen},
|
||||
{KeyboardKey.Insert, LedId.Keyboard_Insert},
|
||||
{KeyboardKey.Delete, LedId.Keyboard_Delete},
|
||||
{KeyboardKey.Help, LedId.Keyboard_Custom15},
|
||||
{KeyboardKey.D0, LedId.Keyboard_0},
|
||||
{KeyboardKey.D1, LedId.Keyboard_1},
|
||||
{KeyboardKey.D2, LedId.Keyboard_2},
|
||||
{KeyboardKey.D3, LedId.Keyboard_3},
|
||||
{KeyboardKey.D4, LedId.Keyboard_4},
|
||||
{KeyboardKey.D5, LedId.Keyboard_5},
|
||||
{KeyboardKey.D6, LedId.Keyboard_6},
|
||||
{KeyboardKey.D7, LedId.Keyboard_7},
|
||||
{KeyboardKey.D8, LedId.Keyboard_8},
|
||||
{KeyboardKey.D9, LedId.Keyboard_9},
|
||||
{KeyboardKey.A, LedId.Keyboard_A},
|
||||
{KeyboardKey.B, LedId.Keyboard_B},
|
||||
{KeyboardKey.C, LedId.Keyboard_C},
|
||||
{KeyboardKey.D, LedId.Keyboard_D},
|
||||
{KeyboardKey.E, LedId.Keyboard_E},
|
||||
{KeyboardKey.F, LedId.Keyboard_F},
|
||||
{KeyboardKey.G, LedId.Keyboard_G},
|
||||
{KeyboardKey.H, LedId.Keyboard_H},
|
||||
{KeyboardKey.I, LedId.Keyboard_I},
|
||||
{KeyboardKey.J, LedId.Keyboard_J},
|
||||
{KeyboardKey.K, LedId.Keyboard_K},
|
||||
{KeyboardKey.L, LedId.Keyboard_L},
|
||||
{KeyboardKey.M, LedId.Keyboard_M},
|
||||
{KeyboardKey.N, LedId.Keyboard_N},
|
||||
{KeyboardKey.O, LedId.Keyboard_O},
|
||||
{KeyboardKey.P, LedId.Keyboard_P},
|
||||
{KeyboardKey.Q, LedId.Keyboard_Q},
|
||||
{KeyboardKey.R, LedId.Keyboard_R},
|
||||
{KeyboardKey.S, LedId.Keyboard_S},
|
||||
{KeyboardKey.T, LedId.Keyboard_T},
|
||||
{KeyboardKey.U, LedId.Keyboard_U},
|
||||
{KeyboardKey.V, LedId.Keyboard_V},
|
||||
{KeyboardKey.W, LedId.Keyboard_W},
|
||||
{KeyboardKey.X, LedId.Keyboard_X},
|
||||
{KeyboardKey.Y, LedId.Keyboard_Y},
|
||||
{KeyboardKey.Z, LedId.Keyboard_Z},
|
||||
{KeyboardKey.LWin, LedId.Keyboard_LeftGui},
|
||||
{KeyboardKey.RWin, LedId.Keyboard_RightGui},
|
||||
{KeyboardKey.Apps, LedId.Keyboard_Application},
|
||||
{KeyboardKey.Sleep, LedId.Keyboard_Custom16},
|
||||
{KeyboardKey.NumPad0, LedId.Keyboard_Num0},
|
||||
{KeyboardKey.NumPad1, LedId.Keyboard_Num1},
|
||||
{KeyboardKey.NumPad2, LedId.Keyboard_Num2},
|
||||
{KeyboardKey.NumPad3, LedId.Keyboard_Num3},
|
||||
{KeyboardKey.NumPad4, LedId.Keyboard_Num4},
|
||||
{KeyboardKey.NumPad5, LedId.Keyboard_Num5},
|
||||
{KeyboardKey.NumPad6, LedId.Keyboard_Num6},
|
||||
{KeyboardKey.NumPad7, LedId.Keyboard_Num7},
|
||||
{KeyboardKey.NumPad8, LedId.Keyboard_Num8},
|
||||
{KeyboardKey.NumPad9, LedId.Keyboard_Num9},
|
||||
{KeyboardKey.Multiply, LedId.Keyboard_NumAsterisk},
|
||||
{KeyboardKey.Add, LedId.Keyboard_NumPlus},
|
||||
{KeyboardKey.Separator, LedId.Keyboard_NumEnter}, // unverified
|
||||
{KeyboardKey.Subtract, LedId.Keyboard_NumMinus},
|
||||
{KeyboardKey.Decimal, LedId.Keyboard_NumPeriodAndDelete},
|
||||
{KeyboardKey.Divide, LedId.Keyboard_NumSlash},
|
||||
{KeyboardKey.F1, LedId.Keyboard_F1},
|
||||
{KeyboardKey.F2, LedId.Keyboard_F2},
|
||||
{KeyboardKey.F3, LedId.Keyboard_F3},
|
||||
{KeyboardKey.F4, LedId.Keyboard_F4},
|
||||
{KeyboardKey.F5, LedId.Keyboard_F5},
|
||||
{KeyboardKey.F6, LedId.Keyboard_F6},
|
||||
{KeyboardKey.F7, LedId.Keyboard_F7},
|
||||
{KeyboardKey.F8, LedId.Keyboard_F8},
|
||||
{KeyboardKey.F9, LedId.Keyboard_F9},
|
||||
{KeyboardKey.F10, LedId.Keyboard_F10},
|
||||
{KeyboardKey.F11, LedId.Keyboard_F11},
|
||||
{KeyboardKey.F12, LedId.Keyboard_F12},
|
||||
{KeyboardKey.F13, LedId.Keyboard_Custom17},
|
||||
{KeyboardKey.F14, LedId.Keyboard_Custom18},
|
||||
{KeyboardKey.F15, LedId.Keyboard_Custom19},
|
||||
{KeyboardKey.F16, LedId.Keyboard_Custom20},
|
||||
{KeyboardKey.F17, LedId.Keyboard_Custom21},
|
||||
{KeyboardKey.F18, LedId.Keyboard_Custom22},
|
||||
{KeyboardKey.F19, LedId.Keyboard_Custom23},
|
||||
{KeyboardKey.F20, LedId.Keyboard_Custom24},
|
||||
{KeyboardKey.F21, LedId.Keyboard_Custom25},
|
||||
{KeyboardKey.F22, LedId.Keyboard_Custom26},
|
||||
{KeyboardKey.F23, LedId.Keyboard_Custom27},
|
||||
{KeyboardKey.F24, LedId.Keyboard_Custom28},
|
||||
{KeyboardKey.NumLock, LedId.Keyboard_NumLock},
|
||||
{KeyboardKey.Scroll, LedId.Keyboard_ScrollLock},
|
||||
{KeyboardKey.LeftShift, LedId.Keyboard_LeftShift},
|
||||
{KeyboardKey.RightShift, LedId.Keyboard_RightShift},
|
||||
{KeyboardKey.LeftCtrl, LedId.Keyboard_LeftCtrl},
|
||||
{KeyboardKey.RightCtrl, LedId.Keyboard_RightCtrl},
|
||||
{KeyboardKey.LeftAlt, LedId.Keyboard_LeftAlt},
|
||||
{KeyboardKey.RightAlt, LedId.Keyboard_RightAlt},
|
||||
{KeyboardKey.BrowserBack, LedId.Keyboard_Custom29},
|
||||
{KeyboardKey.BrowserForward, LedId.Keyboard_Custom30},
|
||||
{KeyboardKey.BrowserRefresh, LedId.Keyboard_Custom31},
|
||||
{KeyboardKey.BrowserStop, LedId.Keyboard_Custom32},
|
||||
{KeyboardKey.BrowserSearch, LedId.Keyboard_Custom33},
|
||||
{KeyboardKey.BrowserFavorites, LedId.Keyboard_Custom34},
|
||||
{KeyboardKey.BrowserHome, LedId.Keyboard_Custom35},
|
||||
{KeyboardKey.VolumeMute, LedId.Keyboard_MediaMute},
|
||||
{KeyboardKey.VolumeDown, LedId.Keyboard_MediaVolumeDown},
|
||||
{KeyboardKey.VolumeUp, LedId.Keyboard_MediaVolumeUp},
|
||||
{KeyboardKey.MediaNextTrack, LedId.Keyboard_MediaNextTrack},
|
||||
{KeyboardKey.MediaPreviousTrack, LedId.Keyboard_MediaPreviousTrack},
|
||||
{KeyboardKey.MediaStop, LedId.Keyboard_MediaStop},
|
||||
{KeyboardKey.MediaPlayPause, LedId.Keyboard_MediaPlay},
|
||||
{KeyboardKey.LaunchMail, LedId.Keyboard_Custom36},
|
||||
{KeyboardKey.SelectMedia, LedId.Keyboard_Custom37},
|
||||
{KeyboardKey.LaunchApplication1, LedId.Keyboard_Custom38},
|
||||
{KeyboardKey.LaunchApplication2, LedId.Keyboard_Custom39},
|
||||
{KeyboardKey.OemSemicolon, LedId.Keyboard_SemicolonAndColon},
|
||||
{KeyboardKey.OemPlus, LedId.Keyboard_EqualsAndPlus},
|
||||
{KeyboardKey.OemMinus, LedId.Keyboard_MinusAndUnderscore},
|
||||
{KeyboardKey.OemComma, LedId.Keyboard_CommaAndLessThan},
|
||||
{KeyboardKey.OemPeriod, LedId.Keyboard_PeriodAndBiggerThan},
|
||||
{KeyboardKey.OemQuestion, LedId.Keyboard_SlashAndQuestionMark},
|
||||
{KeyboardKey.OemTilde, LedId.Keyboard_GraveAccentAndTilde},
|
||||
{KeyboardKey.AbntC1, LedId.Keyboard_Custom40},
|
||||
{KeyboardKey.AbntC2, LedId.Keyboard_Custom41},
|
||||
{KeyboardKey.OemOpenBrackets, LedId.Keyboard_BracketLeft},
|
||||
{KeyboardKey.OemPipe, LedId.Keyboard_Backslash},
|
||||
{KeyboardKey.OemCloseBrackets, LedId.Keyboard_BracketRight},
|
||||
{KeyboardKey.OemQuotes, LedId.Keyboard_ApostropheAndDoubleQuote},
|
||||
{KeyboardKey.OemBackslash, LedId.Keyboard_Custom42}, // unverified
|
||||
{KeyboardKey.ImeProcessed, LedId.Keyboard_Custom43},
|
||||
{KeyboardKey.System, LedId.Keyboard_Custom44},
|
||||
{KeyboardKey.OemAttn, LedId.Keyboard_Custom45},
|
||||
{KeyboardKey.OemFinish, LedId.Keyboard_Custom46},
|
||||
{KeyboardKey.OemCopy, LedId.Keyboard_Custom47},
|
||||
{KeyboardKey.OemAuto, LedId.Keyboard_Custom48},
|
||||
{KeyboardKey.OemEnlw, LedId.Keyboard_Custom49},
|
||||
{KeyboardKey.OemBackTab, LedId.Keyboard_Custom50},
|
||||
{KeyboardKey.Attn, LedId.Keyboard_Custom51},
|
||||
{KeyboardKey.CrSel, LedId.Keyboard_Custom52},
|
||||
{KeyboardKey.ExSel, LedId.Keyboard_Custom53},
|
||||
{KeyboardKey.EraseEof, LedId.Keyboard_Custom54},
|
||||
{KeyboardKey.Play, LedId.Keyboard_MediaPlay},
|
||||
{KeyboardKey.Zoom, LedId.Keyboard_Custom55},
|
||||
{KeyboardKey.NoName, LedId.Keyboard_Custom56},
|
||||
{KeyboardKey.Pa1, LedId.Keyboard_Custom57},
|
||||
{KeyboardKey.OemClear, LedId.Keyboard_Custom58},
|
||||
{KeyboardKey.DeadCharProcessed, LedId.Keyboard_Custom59},
|
||||
{KeyboardKey.NumPadEnter, LedId.Keyboard_NumEnter}
|
||||
};
|
||||
|
||||
internal static readonly Dictionary<MouseButton, LedId> MouseButtonLedIdMap = new Dictionary<MouseButton, LedId>
|
||||
{
|
||||
{MouseButton.Left, LedId.Mouse1},
|
||||
{MouseButton.Middle, LedId.Mouse2},
|
||||
{MouseButton.Right, LedId.Mouse3},
|
||||
{MouseButton.Button4, LedId.Mouse4},
|
||||
{MouseButton.Button5, LedId.Mouse5}
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -12,15 +12,72 @@ namespace Artemis.Core.Services
|
||||
/// Occurs when the input provided has received keyboard data
|
||||
/// </summary>
|
||||
public event EventHandler<InputProviderKeyboardEventArgs>? KeyboardDataReceived;
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Invokes the <see cref="KeyboardDataReceived" /> event
|
||||
/// Occurs when the input provided has received mouse button data
|
||||
/// </summary>
|
||||
public event EventHandler<InputProviderMouseButtonEventArgs>? MouseButtonDataReceived;
|
||||
|
||||
/// <summary>
|
||||
/// Occurs when the input provided has received mouse scroll data
|
||||
/// </summary>
|
||||
public event EventHandler<InputProviderMouseScrollEventArgs>? MouseScrollDataReceived;
|
||||
|
||||
/// <summary>
|
||||
/// Occurs when the input provided has received mouse move data
|
||||
/// </summary>
|
||||
public event EventHandler<InputProviderMouseMoveEventArgs>? MouseMoveDataReceived;
|
||||
|
||||
/// <summary>
|
||||
/// Occurs when the input provided received a device identifier
|
||||
/// </summary>
|
||||
public event EventHandler<object>? IdentifierReceived;
|
||||
|
||||
/// <summary>
|
||||
/// Invokes the <see cref="KeyboardDataReceived" /> event which the <see cref="IInputService" /> listens to as long as
|
||||
/// this provider is registered
|
||||
/// </summary>
|
||||
protected virtual void OnKeyboardDataReceived(InputProviderKeyboardEventArgs e)
|
||||
{
|
||||
KeyboardDataReceived?.Invoke(this, e);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Invokes the <see cref="MouseButtonDataReceived" /> event which the <see cref="IInputService" /> listens to as long
|
||||
/// as this provider is registered
|
||||
/// </summary>
|
||||
protected virtual void OnMouseButtonDataReceived(InputProviderMouseButtonEventArgs e)
|
||||
{
|
||||
MouseButtonDataReceived?.Invoke(this, e);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Invokes the <see cref="MouseScrollDataReceived" /> event which the <see cref="IInputService" /> listens to as long
|
||||
/// as this provider is registered
|
||||
/// </summary>
|
||||
protected virtual void OnMouseScrollDataReceived(InputProviderMouseScrollEventArgs e)
|
||||
{
|
||||
MouseScrollDataReceived?.Invoke(this, e);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Invokes the <see cref="MouseMoveDataReceived" /> event which the <see cref="IInputService" /> listens to as long as
|
||||
/// this provider is registered
|
||||
/// </summary>
|
||||
protected virtual void OnMouseMoveDataReceived(InputProviderMouseMoveEventArgs e)
|
||||
{
|
||||
MouseMoveDataReceived?.Invoke(this, e);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Invokes the <see cref="IdentifierReceived" /> event which the <see cref="IInputService" /> listens to as long as
|
||||
/// this provider is registered
|
||||
/// </summary>
|
||||
protected virtual void OnIdentifierReceived(object identifier)
|
||||
{
|
||||
IdentifierReceived?.Invoke(this, identifier);
|
||||
}
|
||||
|
||||
#region IDisposable
|
||||
|
||||
/// <summary>
|
||||
|
||||
@ -1,4 +1,6 @@
|
||||
using System.Collections.Generic;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using RGB.NET.Core;
|
||||
using Serilog;
|
||||
|
||||
@ -7,18 +9,31 @@ namespace Artemis.Core.Services
|
||||
internal class InputService : IInputService
|
||||
{
|
||||
private readonly ILogger _logger;
|
||||
private readonly ISurfaceService _surfaceService;
|
||||
private readonly List<InputProvider> _inputProviders;
|
||||
|
||||
public InputService(ILogger logger)
|
||||
public InputService(ILogger logger, ISurfaceService surfaceService)
|
||||
{
|
||||
_logger = logger;
|
||||
_surfaceService = surfaceService;
|
||||
_inputProviders = new List<InputProvider>();
|
||||
_keyboardModifier = new Dictionary<ArtemisDevice, KeyboardModifierKeys>();
|
||||
_deviceCache = new Dictionary<Tuple<InputProvider, object>, ArtemisDevice>();
|
||||
_devices = new List<ArtemisDevice>();
|
||||
|
||||
_surfaceService.ActiveSurfaceConfigurationSelected += SurfaceConfigurationChanged;
|
||||
_surfaceService.SurfaceConfigurationUpdated += SurfaceConfigurationChanged;
|
||||
BustIdentifierCache();
|
||||
}
|
||||
|
||||
public void AddInputProvider(InputProvider inputProvider)
|
||||
{
|
||||
_inputProviders.Add(inputProvider);
|
||||
inputProvider.IdentifierReceived += InputProviderOnIdentifierReceived;
|
||||
inputProvider.KeyboardDataReceived += InputProviderOnKeyboardDataReceived;
|
||||
inputProvider.MouseButtonDataReceived += InputProviderOnMouseButtonDataReceived;
|
||||
inputProvider.MouseScrollDataReceived += InputProviderOnMouseScrollDataReceived;
|
||||
inputProvider.MouseMoveDataReceived += InputProviderOnMouseMoveDataReceived;
|
||||
_inputProviders.Add(inputProvider);
|
||||
}
|
||||
|
||||
public void RemoveInputProvider(InputProvider inputProvider)
|
||||
@ -26,34 +41,253 @@ namespace Artemis.Core.Services
|
||||
if (!_inputProviders.Contains(inputProvider))
|
||||
return;
|
||||
|
||||
_inputProviders.Remove(inputProvider);
|
||||
inputProvider.IdentifierReceived -= InputProviderOnIdentifierReceived;
|
||||
inputProvider.KeyboardDataReceived -= InputProviderOnKeyboardDataReceived;
|
||||
inputProvider.MouseButtonDataReceived -= InputProviderOnMouseButtonDataReceived;
|
||||
inputProvider.MouseScrollDataReceived -= InputProviderOnMouseScrollDataReceived;
|
||||
inputProvider.MouseMoveDataReceived -= InputProviderOnMouseMoveDataReceived;
|
||||
}
|
||||
|
||||
private void InputProviderOnKeyboardDataReceived(object? sender, InputProviderKeyboardEventArgs e)
|
||||
#region Identification
|
||||
|
||||
private readonly Dictionary<Tuple<InputProvider, object>, ArtemisDevice> _deviceCache;
|
||||
private List<ArtemisDevice> _devices;
|
||||
private ArtemisDevice? _cachedFallbackKeyboard;
|
||||
private ArtemisDevice? _cachedFallbackMouse;
|
||||
private ArtemisDevice? _identifyingDevice;
|
||||
|
||||
public void IdentifyDevice(ArtemisDevice device)
|
||||
{
|
||||
if (!(sender is InputProvider inputProvider))
|
||||
_identifyingDevice = device;
|
||||
_logger.Debug("Start identifying device {device}", device);
|
||||
}
|
||||
|
||||
public void StopIdentify()
|
||||
{
|
||||
_logger.Debug("Stop identifying device {device}", _identifyingDevice);
|
||||
|
||||
_identifyingDevice = null;
|
||||
_surfaceService.UpdateSurfaceConfiguration(_surfaceService.ActiveSurface, true);
|
||||
|
||||
BustIdentifierCache();
|
||||
}
|
||||
|
||||
public ArtemisDevice? GetDeviceByIdentifier(InputProvider provider, object identifier, InputFallbackDeviceType fallbackType)
|
||||
{
|
||||
if (provider == null) throw new ArgumentNullException(nameof(provider));
|
||||
if (identifier == null) throw new ArgumentNullException(nameof(identifier));
|
||||
|
||||
// Try cache first
|
||||
ArtemisDevice? cacheMatch = GetDeviceFromCache(provider, identifier);
|
||||
if (cacheMatch != null)
|
||||
return cacheMatch;
|
||||
|
||||
string providerName = provider.GetType().FullName!;
|
||||
ArtemisDevice? match = _devices.FirstOrDefault(m => m.InputIdentifiers.Any(i => Equals(i.InputProvider,providerName) && Equals(i.Identifier, identifier)));
|
||||
|
||||
// If a match was found cache it to speed up the next event and return the match
|
||||
if (match != null)
|
||||
{
|
||||
AddDeviceToCache(match, provider, identifier);
|
||||
return match;
|
||||
}
|
||||
|
||||
// If there is no match, apply our fallback type
|
||||
if (fallbackType == InputFallbackDeviceType.None)
|
||||
return null;
|
||||
if (fallbackType == InputFallbackDeviceType.Keyboard)
|
||||
{
|
||||
if (_cachedFallbackKeyboard != null)
|
||||
return _cachedFallbackKeyboard;
|
||||
_cachedFallbackKeyboard = _surfaceService.ActiveSurface.Devices.FirstOrDefault(d => d.RgbDevice.DeviceInfo.DeviceType == RGBDeviceType.Keyboard);
|
||||
return _cachedFallbackKeyboard;
|
||||
}
|
||||
|
||||
if (fallbackType == InputFallbackDeviceType.Mouse)
|
||||
{
|
||||
if (_cachedFallbackMouse != null)
|
||||
return _cachedFallbackMouse;
|
||||
_cachedFallbackMouse = _surfaceService.ActiveSurface.Devices.FirstOrDefault(d => d.RgbDevice.DeviceInfo.DeviceType == RGBDeviceType.Mouse);
|
||||
return _cachedFallbackMouse;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
public void BustIdentifierCache()
|
||||
{
|
||||
_deviceCache.Clear();
|
||||
_cachedFallbackKeyboard = null;
|
||||
_cachedFallbackMouse = null;
|
||||
|
||||
_devices = _surfaceService.ActiveSurface.Devices.Where(d => d.InputIdentifiers.Any()).ToList();
|
||||
}
|
||||
|
||||
private void AddDeviceToCache(ArtemisDevice match, InputProvider provider, object identifier)
|
||||
{
|
||||
_deviceCache.TryAdd(new Tuple<InputProvider, object>(provider, identifier), match);
|
||||
}
|
||||
|
||||
private ArtemisDevice? GetDeviceFromCache(InputProvider provider, object identifier)
|
||||
{
|
||||
_deviceCache.TryGetValue(new Tuple<InputProvider, object>(provider, identifier), out ArtemisDevice? device);
|
||||
return device;
|
||||
}
|
||||
|
||||
private void SurfaceConfigurationChanged(object? sender, SurfaceConfigurationEventArgs e)
|
||||
{
|
||||
BustIdentifierCache();
|
||||
}
|
||||
|
||||
private void InputProviderOnIdentifierReceived(object? sender, object identifier)
|
||||
{
|
||||
if (_identifyingDevice == null)
|
||||
return;
|
||||
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);
|
||||
string providerName = inputProvider.GetType().FullName!;
|
||||
|
||||
// Remove existing identification
|
||||
_identifyingDevice.InputIdentifiers.RemoveAll(i => i.InputProvider == providerName);
|
||||
_identifyingDevice.InputIdentifiers.Add(new ArtemisDeviceInputIdentifier(providerName, identifier));
|
||||
|
||||
StopIdentify();
|
||||
OnDeviceIdentified();
|
||||
}
|
||||
}
|
||||
|
||||
/// <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);
|
||||
#endregion
|
||||
|
||||
/// <summary>
|
||||
/// Removes an input provided
|
||||
/// </summary>
|
||||
/// <param name="inputProvider">The input provider the remove</param>
|
||||
void RemoveInputProvider(InputProvider inputProvider);
|
||||
#region Keyboard
|
||||
|
||||
private readonly Dictionary<ArtemisDevice, KeyboardModifierKeys> _keyboardModifier;
|
||||
private KeyboardModifierKeys _globalModifiers;
|
||||
|
||||
private void InputProviderOnKeyboardDataReceived(object? sender, InputProviderKeyboardEventArgs e)
|
||||
{
|
||||
KeyboardModifierKeys keyboardModifierKeys = UpdateModifierKeys(e.Device, e.Key, e.IsDown);
|
||||
|
||||
// Get the LED - TODO: leverage a lookup
|
||||
bool foundLedId = InputKeyUtilities.KeyboardKeyLedIdMap.TryGetValue(e.Key, out LedId ledId);
|
||||
ArtemisLed? led = null;
|
||||
if (foundLedId && e.Device != null)
|
||||
led = e.Device.Leds.FirstOrDefault(l => l.RgbLed.Id == ledId);
|
||||
|
||||
// Create the UpDown event args because it can be used for every event
|
||||
KeyboardKeyUpDownEventArgs eventArgs = new KeyboardKeyUpDownEventArgs(e.Device, led, e.Key, keyboardModifierKeys, e.IsDown);
|
||||
OnKeyboardKeyUpDown(eventArgs);
|
||||
if (e.IsDown)
|
||||
OnKeyboardKeyDown(eventArgs);
|
||||
else
|
||||
OnKeyboardKeyUp(eventArgs);
|
||||
|
||||
_logger.Verbose("Keyboard data: LED ID: {ledId}, key: {key}, is down: {isDown}, modifiers: {modifiers}, device: {device} ", ledId, e.Key, e.IsDown, keyboardModifierKeys, e.Device);
|
||||
}
|
||||
|
||||
private KeyboardModifierKeys UpdateModifierKeys(ArtemisDevice? device, KeyboardKey key, in bool isDown)
|
||||
{
|
||||
KeyboardModifierKeys modifiers = _globalModifiers;
|
||||
if (device != null)
|
||||
_keyboardModifier.TryGetValue(device, out modifiers);
|
||||
|
||||
if (key == KeyboardKey.LeftAlt || key == KeyboardKey.RightAlt)
|
||||
{
|
||||
if (isDown)
|
||||
modifiers = modifiers | KeyboardModifierKeys.Alt;
|
||||
else
|
||||
modifiers = modifiers & ~KeyboardModifierKeys.Alt;
|
||||
}
|
||||
else if (key == KeyboardKey.LeftCtrl || key == KeyboardKey.RightCtrl)
|
||||
{
|
||||
if (isDown)
|
||||
modifiers = modifiers | KeyboardModifierKeys.Control;
|
||||
else
|
||||
modifiers = modifiers & ~KeyboardModifierKeys.Control;
|
||||
}
|
||||
else if (key == KeyboardKey.LeftShift || key == KeyboardKey.RightShift)
|
||||
{
|
||||
if (isDown)
|
||||
modifiers = modifiers | KeyboardModifierKeys.Shift;
|
||||
else
|
||||
modifiers = modifiers & ~KeyboardModifierKeys.Shift;
|
||||
}
|
||||
else if (key == KeyboardKey.LWin || key == KeyboardKey.RWin)
|
||||
{
|
||||
if (isDown)
|
||||
modifiers = modifiers | KeyboardModifierKeys.Windows;
|
||||
else
|
||||
modifiers = modifiers & ~KeyboardModifierKeys.Windows;
|
||||
}
|
||||
|
||||
if (device != null)
|
||||
_keyboardModifier[device] = modifiers;
|
||||
else
|
||||
_globalModifiers = modifiers;
|
||||
|
||||
return modifiers;
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Mouse
|
||||
|
||||
private void InputProviderOnMouseButtonDataReceived(object? sender, InputProviderMouseButtonEventArgs e)
|
||||
{
|
||||
bool foundLedId = InputKeyUtilities.MouseButtonLedIdMap.TryGetValue(e.Button, out LedId ledId);
|
||||
// _logger.Verbose("Mouse button data: LED ID: {ledId}, button: {button}, is down: {isDown}, device: {device} ", ledId, e.Button, e.IsDown, e.Device);
|
||||
}
|
||||
|
||||
private void InputProviderOnMouseScrollDataReceived(object? sender, InputProviderMouseScrollEventArgs e)
|
||||
{
|
||||
// _logger.Verbose("Mouse scroll data: Direction: {direction}, delta: {delta}, device: {device} ", e.Direction, e.Delta, e.Device);
|
||||
}
|
||||
|
||||
private void InputProviderOnMouseMoveDataReceived(object? sender, InputProviderMouseMoveEventArgs e)
|
||||
{
|
||||
// _logger.Verbose("Mouse move data: XY: {X},{Y} - delta XY: {deltaX},{deltaY} - device: {device} ", e.CursorX, e.CursorY, e.DeltaX, e.DeltaY, e.Device);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Events
|
||||
|
||||
public event EventHandler<KeyboardKeyUpDownEventArgs>? KeyboardKeyUpDown;
|
||||
public event EventHandler<KeyboardEventArgs>? KeyboardKeyDown;
|
||||
public event EventHandler<KeyboardEventArgs>? KeyboardKeyUp;
|
||||
public event EventHandler? DeviceIdentified;
|
||||
|
||||
protected virtual void OnKeyboardKeyUpDown(KeyboardKeyUpDownEventArgs e)
|
||||
{
|
||||
KeyboardKeyUpDown?.Invoke(this, e);
|
||||
}
|
||||
|
||||
protected virtual void OnKeyboardKeyDown(KeyboardEventArgs e)
|
||||
{
|
||||
KeyboardKeyDown?.Invoke(this, e);
|
||||
}
|
||||
|
||||
protected virtual void OnKeyboardKeyUp(KeyboardEventArgs e)
|
||||
{
|
||||
KeyboardKeyUp?.Invoke(this, e);
|
||||
}
|
||||
|
||||
protected virtual void OnDeviceIdentified()
|
||||
{
|
||||
DeviceIdentified?.Invoke(this, EventArgs.Empty);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region IDisposable
|
||||
|
||||
/// <inheritdoc />
|
||||
public void Dispose()
|
||||
{
|
||||
while (_inputProviders.Any())
|
||||
RemoveInputProvider(_inputProviders.First());
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
75
src/Artemis.Core/Services/Input/Interfaces/IInputService.cs
Normal file
75
src/Artemis.Core/Services/Input/Interfaces/IInputService.cs
Normal file
@ -0,0 +1,75 @@
|
||||
using System;
|
||||
|
||||
namespace Artemis.Core.Services
|
||||
{
|
||||
/// <summary>
|
||||
/// A service that allows you to interact with keyboard and mice input events
|
||||
/// </summary>
|
||||
public interface IInputService : IArtemisService, IDisposable
|
||||
{
|
||||
/// <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);
|
||||
|
||||
/// <summary>
|
||||
/// Identifies the provided <paramref name="device" /> by assigning the next received device identification to it
|
||||
/// </summary>
|
||||
/// <param name="device">The device to identify</param>
|
||||
void IdentifyDevice(ArtemisDevice device);
|
||||
|
||||
/// <summary>
|
||||
/// Cancels identifying the device last passed to <see cref="IdentifyDevice" />
|
||||
/// </summary>
|
||||
void StopIdentify();
|
||||
|
||||
#region Events
|
||||
|
||||
/// <summary>
|
||||
/// Occurs whenever a key on a keyboard was pressed or released
|
||||
/// </summary>
|
||||
event EventHandler<KeyboardKeyUpDownEventArgs> KeyboardKeyUpDown;
|
||||
|
||||
/// <summary>
|
||||
/// Occurs whenever a key on a keyboard was pressed
|
||||
/// </summary>
|
||||
event EventHandler<KeyboardEventArgs> KeyboardKeyDown;
|
||||
|
||||
/// <summary>
|
||||
/// Occurs whenever a key on a keyboard was released
|
||||
/// </summary>
|
||||
event EventHandler<KeyboardEventArgs> KeyboardKeyUp;
|
||||
|
||||
/// <summary>
|
||||
/// Occurs when a device has been identified after calling <see cref="IdentifyDevice" />
|
||||
/// </summary>
|
||||
public event EventHandler DeviceIdentified;
|
||||
|
||||
#endregion
|
||||
|
||||
#region Identification
|
||||
|
||||
/// <summary>
|
||||
/// Attempts to identify the device using the provided <paramref name="identifier" />
|
||||
/// </summary>
|
||||
/// <param name="provider">The input provider to identify the device for</param>
|
||||
/// <param name="identifier">The value to use to identify the device</param>
|
||||
/// <param name="fallbackType">A device type to fall back to if no match is found</param>
|
||||
/// <returns>If found, the Artemis device matching the provider and identifier</returns>
|
||||
ArtemisDevice? GetDeviceByIdentifier(InputProvider provider, object identifier, InputFallbackDeviceType fallbackType);
|
||||
|
||||
/// <summary>
|
||||
/// Clears the identifier cache
|
||||
/// </summary>
|
||||
void BustIdentifierCache();
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
@ -1,13 +1,12 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Runtime.InteropServices;
|
||||
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;
|
||||
using MouseButton = Artemis.Core.Services.MouseButton;
|
||||
|
||||
namespace Artemis.UI.InputProviders
|
||||
{
|
||||
@ -15,25 +14,19 @@ namespace Artemis.UI.InputProviders
|
||||
{
|
||||
private const int WM_INPUT = 0x00FF;
|
||||
|
||||
private readonly ISurfaceService _surfaceService;
|
||||
private List<ArtemisDevice> _keyboards;
|
||||
private readonly IInputService _inputService;
|
||||
private DateTime _lastMouseUpdate;
|
||||
private List<ArtemisDevice> _mice;
|
||||
private SpongeWindow _sponge;
|
||||
|
||||
public NativeWindowInputProvider(ISurfaceService surfaceService)
|
||||
public NativeWindowInputProvider(IInputService inputService)
|
||||
{
|
||||
_surfaceService = surfaceService;
|
||||
_inputService = inputService;
|
||||
|
||||
_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
|
||||
@ -45,9 +38,6 @@ namespace Artemis.UI.InputProviders
|
||||
{
|
||||
_sponge?.DestroyHandle();
|
||||
_sponge = null;
|
||||
|
||||
_surfaceService.ActiveSurfaceConfigurationSelected -= SurfaceConfigurationChanged;
|
||||
_surfaceService.SurfaceConfigurationUpdated -= SurfaceConfigurationChanged;
|
||||
}
|
||||
|
||||
base.Dispose(disposing);
|
||||
@ -55,17 +45,6 @@ namespace Artemis.UI.InputProviders
|
||||
|
||||
#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)
|
||||
@ -75,67 +54,168 @@ namespace Artemis.UI.InputProviders
|
||||
switch (data)
|
||||
{
|
||||
case RawInputMouseData mouse:
|
||||
HandleMouseData(mouse);
|
||||
HandleMouseData(data, mouse);
|
||||
break;
|
||||
case RawInputKeyboardData keyboard:
|
||||
HandleKeyboardData(keyboard);
|
||||
HandleKeyboardData(data, keyboard);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
private void HandleKeyboardData(RawInputKeyboardData data)
|
||||
#region Keyboard
|
||||
|
||||
private void HandleKeyboardData(RawInputData data, RawInputKeyboardData keyboardData)
|
||||
{
|
||||
// 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}");
|
||||
|
||||
KeyboardKey key = (KeyboardKey) KeyInterop.KeyFromVirtualKey(keyboardData.Keyboard.VirutalKey);
|
||||
// Debug.WriteLine($"VK: {key} ({keyboardData.Keyboard.VirutalKey}), Flags: {keyboardData.Keyboard.Flags}, Scan code: {keyboardData.Keyboard.ScanCode}");
|
||||
|
||||
// Sometimes we get double hits and they resolve to None, ignore those
|
||||
if (key == InputKey.None)
|
||||
if (key == KeyboardKey.None)
|
||||
return;
|
||||
|
||||
// Right alt triggers LeftCtrl with a different scan code for some reason, ignore those
|
||||
if (key == InputKey.LeftCtrl && data.Keyboard.ScanCode == 56)
|
||||
if (key == KeyboardKey.LeftCtrl && keyboardData.Keyboard.ScanCode == 56)
|
||||
return;
|
||||
|
||||
string identifier = data.Device?.DevicePath;
|
||||
|
||||
// Let the core know there is an identifier so it can store new identifications if applicable
|
||||
if (identifier != null)
|
||||
OnIdentifierReceived(identifier);
|
||||
|
||||
ArtemisDevice device = null;
|
||||
if (identifier != null)
|
||||
device = _inputService.GetDeviceByIdentifier(this, identifier, InputFallbackDeviceType.Keyboard);
|
||||
|
||||
// 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 (keyboardData.Keyboard.Flags == RawKeyboardFlags.LeftKey || keyboardData.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 == KeyboardKey.Enter)
|
||||
key = KeyboardKey.NumPadEnter;
|
||||
if (key == KeyboardKey.LeftCtrl)
|
||||
key = KeyboardKey.RightCtrl;
|
||||
if (key == KeyboardKey.LeftAlt)
|
||||
key = KeyboardKey.RightAlt;
|
||||
}
|
||||
|
||||
if (key == InputKey.LeftShift && data.Keyboard.ScanCode == 54)
|
||||
key = InputKey.RightShift;
|
||||
if (key == KeyboardKey.LeftShift && keyboardData.Keyboard.ScanCode == 54)
|
||||
key = KeyboardKey.RightShift;
|
||||
|
||||
bool isDown = data.Keyboard.Flags != RawKeyboardFlags.Up &&
|
||||
data.Keyboard.Flags != (RawKeyboardFlags.Up | RawKeyboardFlags.LeftKey) &&
|
||||
data.Keyboard.Flags != (RawKeyboardFlags.Up | RawKeyboardFlags.RightKey);
|
||||
bool isDown = keyboardData.Keyboard.Flags != RawKeyboardFlags.Up &&
|
||||
keyboardData.Keyboard.Flags != (RawKeyboardFlags.Up | RawKeyboardFlags.LeftKey) &&
|
||||
keyboardData.Keyboard.Flags != (RawKeyboardFlags.Up | RawKeyboardFlags.RightKey);
|
||||
|
||||
OnKeyboardDataReceived(new InputProviderKeyboardEventArgs(match, key, isDown));
|
||||
OnKeyboardDataReceived(new InputProviderKeyboardEventArgs(device, key, isDown));
|
||||
}
|
||||
|
||||
private void HandleMouseData(RawInputMouseData data)
|
||||
#endregion
|
||||
|
||||
#region Mouse
|
||||
|
||||
private int _mouseDeltaX;
|
||||
private int _mouseDeltaY;
|
||||
|
||||
private void HandleMouseData(RawInputData data, RawInputMouseData mouseData)
|
||||
{
|
||||
// Only handle mouse movement 25 times per second
|
||||
if (data.Mouse.Buttons == RawMouseButtonFlags.None)
|
||||
// Only submit mouse movement 25 times per second but increment the delta
|
||||
// This can create a small inaccuracy of course, but Artemis is not a shooter :')
|
||||
if (mouseData.Mouse.Buttons == RawMouseButtonFlags.None)
|
||||
{
|
||||
_mouseDeltaX += mouseData.Mouse.LastX;
|
||||
_mouseDeltaY += mouseData.Mouse.LastY;
|
||||
if (DateTime.Now - _lastMouseUpdate < TimeSpan.FromMilliseconds(40))
|
||||
return;
|
||||
}
|
||||
|
||||
_lastMouseUpdate = DateTime.Now;
|
||||
ArtemisDevice device = null;
|
||||
string identifier = data.Device?.DevicePath;
|
||||
if (identifier != null)
|
||||
device = _inputService.GetDeviceByIdentifier(this, identifier, InputFallbackDeviceType.Mouse);
|
||||
|
||||
// Get the keyboard that submitted the data
|
||||
ArtemisDevice match = _mice?.FirstOrDefault();
|
||||
if (match == null)
|
||||
// Debug.WriteLine($"Buttons: {data.Mouse.Buttons}, Data: {data.Mouse.ButtonData}, Flags: {data.Mouse.Flags}, XY: {data.Mouse.LastX},{data.Mouse.LastY}");
|
||||
|
||||
// Movement
|
||||
if (mouseData.Mouse.Buttons == RawMouseButtonFlags.None)
|
||||
{
|
||||
Win32Point cursorPosition = GetCursorPosition();
|
||||
OnMouseMoveDataReceived(new InputProviderMouseMoveEventArgs(device, cursorPosition.X, cursorPosition.Y, _mouseDeltaX, _mouseDeltaY));
|
||||
_mouseDeltaX = 0;
|
||||
_mouseDeltaY = 0;
|
||||
_lastMouseUpdate = DateTime.Now;
|
||||
return;
|
||||
}
|
||||
|
||||
// Now we know its not movement, let the core know there is an identifier so it can store new identifications if applicable
|
||||
if (identifier != null)
|
||||
OnIdentifierReceived(identifier);
|
||||
|
||||
// Scrolling
|
||||
if (mouseData.Mouse.ButtonData != 0)
|
||||
{
|
||||
if (mouseData.Mouse.Buttons == RawMouseButtonFlags.MouseWheel)
|
||||
OnMouseScrollDataReceived(new InputProviderMouseScrollEventArgs(device, MouseScrollDirection.Vertical, mouseData.Mouse.ButtonData));
|
||||
else if (mouseData.Mouse.Buttons == RawMouseButtonFlags.MouseHorizontalWheel)
|
||||
OnMouseScrollDataReceived(new InputProviderMouseScrollEventArgs(device, MouseScrollDirection.Horizontal, mouseData.Mouse.ButtonData));
|
||||
return;
|
||||
}
|
||||
|
||||
// Button presses
|
||||
MouseButton button = MouseButton.Left;
|
||||
bool isDown = false;
|
||||
|
||||
// Left
|
||||
if (DetermineMouseButton(mouseData, RawMouseButtonFlags.LeftButtonDown, RawMouseButtonFlags.LeftButtonUp, ref isDown))
|
||||
button = MouseButton.Left;
|
||||
// Middle
|
||||
else if (DetermineMouseButton(mouseData, RawMouseButtonFlags.MiddleButtonDown, RawMouseButtonFlags.MiddleButtonUp, ref isDown))
|
||||
button = MouseButton.Middle;
|
||||
// Right
|
||||
else if (DetermineMouseButton(mouseData, RawMouseButtonFlags.RightButtonDown, RawMouseButtonFlags.RightButtonUp, ref isDown))
|
||||
button = MouseButton.Right;
|
||||
// Button 4
|
||||
else if (DetermineMouseButton(mouseData, RawMouseButtonFlags.Button4Down, RawMouseButtonFlags.Button4Up, ref isDown))
|
||||
button = MouseButton.Button4;
|
||||
else if (DetermineMouseButton(mouseData, RawMouseButtonFlags.Button5Down, RawMouseButtonFlags.Button5Up, ref isDown))
|
||||
button = MouseButton.Button5;
|
||||
|
||||
OnMouseButtonDataReceived(new InputProviderMouseButtonEventArgs(device, button, isDown));
|
||||
}
|
||||
|
||||
private bool DetermineMouseButton(RawInputMouseData data, RawMouseButtonFlags downButton, RawMouseButtonFlags upButton, ref bool isDown)
|
||||
{
|
||||
if (data.Mouse.Buttons == downButton || data.Mouse.Buttons == upButton)
|
||||
{
|
||||
isDown = data.Mouse.Buttons == downButton;
|
||||
return true;
|
||||
}
|
||||
|
||||
isDown = false;
|
||||
return false;
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Native
|
||||
|
||||
[DllImport("user32.dll")]
|
||||
[return: MarshalAs(UnmanagedType.Bool)]
|
||||
private static extern bool GetCursorPos(ref Win32Point pt);
|
||||
|
||||
[StructLayout(LayoutKind.Sequential)]
|
||||
private struct Win32Point
|
||||
{
|
||||
public readonly int X;
|
||||
public readonly int Y;
|
||||
}
|
||||
|
||||
private static Win32Point GetCursorPosition()
|
||||
{
|
||||
Win32Point w32Mouse = new Win32Point();
|
||||
GetCursorPos(ref w32Mouse);
|
||||
|
||||
return w32Mouse;
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
@ -5,6 +5,7 @@ using Artemis.Core.Services;
|
||||
using Humanizer;
|
||||
using MaterialDesignExtensions.Controls;
|
||||
using Stylet;
|
||||
using MouseButton = System.Windows.Input.MouseButton;
|
||||
|
||||
namespace Artemis.UI.Screens.Splash
|
||||
{
|
||||
|
||||
@ -0,0 +1,35 @@
|
||||
<UserControl x:Class="Artemis.UI.Screens.SurfaceEditor.Dialogs.SurfaceDeviceDetectInputView"
|
||||
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
|
||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
|
||||
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
|
||||
xmlns:local="clr-namespace:Artemis.UI.Screens.SurfaceEditor.Dialogs"
|
||||
xmlns:materialDesign="http://materialdesigninxaml.net/winfx/xaml/themes"
|
||||
xmlns:s="https://github.com/canton7/Stylet"
|
||||
mc:Ignorable="d"
|
||||
d:DesignHeight="450" d:DesignWidth="800"
|
||||
d:DataContext="{d:DesignInstance {x:Type local:SurfaceDeviceDetectInputViewModel}}">
|
||||
<StackPanel Margin="16" Width="500">
|
||||
<TextBlock Text="{Binding Title}" Style="{StaticResource MaterialDesignHeadline6TextBlock}" Margin="0 0 0 25" TextWrapping="Wrap" />
|
||||
|
||||
<TextBlock Style="{StaticResource MaterialDesignBody1TextBlock}" TextWrapping="Wrap">
|
||||
Press a button/key on your <Run Text="{Binding SurfaceDeviceViewModel.Device.RgbDevice.DeviceInfo.DeviceName, Mode=OneWay}" />
|
||||
that is currently showing a <Bold Foreground="Yellow">yellow</Bold> color.
|
||||
</TextBlock>
|
||||
|
||||
<materialDesign:PackIcon Kind="GestureDoubleTap" Width="300" Height="340" HorizontalAlignment="Center" />
|
||||
|
||||
<TextBlock Style="{StaticResource MaterialDesignBody1TextBlock}" TextWrapping="Wrap">
|
||||
This will teach Artemis to associate button/key presses with this specific device.
|
||||
</TextBlock>
|
||||
|
||||
<Button HorizontalAlignment="Right" Style="{StaticResource MaterialDesignFlatButton}" IsCancel="True" Margin="0 8 8 0" Command="{s:Action Cancel}">
|
||||
<Button.CommandParameter>
|
||||
<system:Boolean xmlns:system="clr-namespace:System;assembly=mscorlib">
|
||||
False
|
||||
</system:Boolean>
|
||||
</Button.CommandParameter>
|
||||
CANCEL
|
||||
</Button>
|
||||
</StackPanel>
|
||||
</UserControl>
|
||||
@ -0,0 +1,65 @@
|
||||
using System;
|
||||
using System.Linq;
|
||||
using Artemis.Core.Services;
|
||||
using Artemis.UI.Screens.SurfaceEditor.Visualization;
|
||||
using Artemis.UI.Shared.Services;
|
||||
using MaterialDesignThemes.Wpf;
|
||||
using RGB.NET.Brushes;
|
||||
using RGB.NET.Core;
|
||||
using RGB.NET.Groups;
|
||||
|
||||
namespace Artemis.UI.Screens.SurfaceEditor.Dialogs
|
||||
{
|
||||
public class SurfaceDeviceDetectInputViewModel : DialogViewModelBase
|
||||
{
|
||||
private readonly IInputService _inputService;
|
||||
private readonly ISnackbarMessageQueue _mainMessageQueue;
|
||||
private string _title;
|
||||
private ListLedGroup _ledGroup;
|
||||
|
||||
public SurfaceDeviceDetectInputViewModel(SurfaceDeviceViewModel surfaceDeviceViewModel, IInputService inputService, ISnackbarMessageQueue mainMessageQueue)
|
||||
{
|
||||
SurfaceDeviceViewModel = surfaceDeviceViewModel;
|
||||
Title = $"{SurfaceDeviceViewModel.Device.RgbDevice.DeviceInfo.DeviceName} - Detect input";
|
||||
|
||||
// Create a LED group way at the top
|
||||
_ledGroup = new ListLedGroup(SurfaceDeviceViewModel.Device.Leds.Select(l => l.RgbLed))
|
||||
{
|
||||
Brush = new SolidColorBrush(new Color(255, 255, 0)),
|
||||
ZIndex = 999
|
||||
};
|
||||
|
||||
|
||||
_inputService = inputService;
|
||||
_mainMessageQueue = mainMessageQueue;
|
||||
_inputService.IdentifyDevice(surfaceDeviceViewModel.Device);
|
||||
_inputService.DeviceIdentified += InputServiceOnDeviceIdentified;
|
||||
}
|
||||
|
||||
public SurfaceDeviceViewModel SurfaceDeviceViewModel { get; }
|
||||
|
||||
public string Title
|
||||
{
|
||||
get => _title;
|
||||
set => SetAndNotify(ref _title, value);
|
||||
}
|
||||
|
||||
public override void OnDialogClosed(object sender, DialogClosingEventArgs e)
|
||||
{
|
||||
base.OnDialogClosed(sender, e);
|
||||
_inputService.DeviceIdentified -= InputServiceOnDeviceIdentified;
|
||||
_ledGroup.Detach();
|
||||
}
|
||||
|
||||
public void Cancel()
|
||||
{
|
||||
Session?.Close(false);
|
||||
}
|
||||
|
||||
private void InputServiceOnDeviceIdentified(object sender, EventArgs e)
|
||||
{
|
||||
Session?.Close(true);
|
||||
_mainMessageQueue.Enqueue("Device identified.");
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -144,6 +144,14 @@
|
||||
</MenuItem.Icon>
|
||||
</MenuItem>
|
||||
<Separator />
|
||||
<MenuItem Header="Identify input"
|
||||
Command="{s:Action DetectInput}"
|
||||
CommandParameter="{Binding}"
|
||||
ToolTip="Teach Artemis which keypresses and/or button presses belong to this device">
|
||||
<MenuItem.Icon>
|
||||
<materialDesign:PackIcon Kind="GestureDoubleTap" />
|
||||
</MenuItem.Icon>
|
||||
</MenuItem>
|
||||
<MenuItem Header="View properties" Command="{s:Action ViewProperties}" CommandParameter="{Binding}">
|
||||
<MenuItem.Icon>
|
||||
<materialDesign:PackIcon Kind="Gear" />
|
||||
|
||||
@ -15,12 +15,14 @@ using Artemis.UI.Screens.SurfaceEditor.Visualization;
|
||||
using Artemis.UI.Shared;
|
||||
using Artemis.UI.Shared.Services;
|
||||
using Stylet;
|
||||
using MouseButton = System.Windows.Input.MouseButton;
|
||||
|
||||
namespace Artemis.UI.Screens.SurfaceEditor
|
||||
{
|
||||
public class SurfaceEditorViewModel : Screen, IMainScreenViewModel
|
||||
{
|
||||
private readonly IDeviceService _deviceService;
|
||||
private readonly IInputService _inputService;
|
||||
private readonly IDialogService _dialogService;
|
||||
private readonly IRgbService _rgbService;
|
||||
private readonly ISettingsService _settingsService;
|
||||
@ -33,8 +35,12 @@ namespace Artemis.UI.Screens.SurfaceEditor
|
||||
private ObservableCollection<ArtemisSurface> _surfaceConfigurations;
|
||||
private PluginSetting<GridLength> _surfaceListWidth;
|
||||
|
||||
public SurfaceEditorViewModel(IRgbService rgbService, ISurfaceService surfaceService, IDialogService dialogService, ISettingsService settingsService,
|
||||
IDeviceService deviceService)
|
||||
public SurfaceEditorViewModel(IRgbService rgbService,
|
||||
ISurfaceService surfaceService,
|
||||
IDialogService dialogService,
|
||||
ISettingsService settingsService,
|
||||
IDeviceService deviceService,
|
||||
IInputService inputService)
|
||||
{
|
||||
DisplayName = "Surface Editor";
|
||||
|
||||
@ -49,6 +55,7 @@ namespace Artemis.UI.Screens.SurfaceEditor
|
||||
_dialogService = dialogService;
|
||||
_settingsService = settingsService;
|
||||
_deviceService = deviceService;
|
||||
_inputService = inputService;
|
||||
}
|
||||
|
||||
public ObservableCollection<SurfaceDeviceViewModel> Devices
|
||||
@ -288,6 +295,17 @@ namespace Artemis.UI.Screens.SurfaceEditor
|
||||
_surfaceService.UpdateSurfaceConfiguration(SelectedSurface, true);
|
||||
}
|
||||
|
||||
public async Task DetectInput(SurfaceDeviceViewModel surfaceDeviceViewModel)
|
||||
{
|
||||
object madeChanges = await _dialogService.ShowDialog<SurfaceDeviceDetectInputViewModel>(new Dictionary<string, object>
|
||||
{
|
||||
{"surfaceDeviceViewModel", surfaceDeviceViewModel}
|
||||
});
|
||||
|
||||
if ((bool)madeChanges)
|
||||
_surfaceService.UpdateSurfaceConfiguration(SelectedSurface, true);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Selection
|
||||
|
||||
@ -85,7 +85,7 @@ namespace Artemis.UI.Services
|
||||
|
||||
public void RegisterInputProvider()
|
||||
{
|
||||
_inputService.AddInputProvider(new NativeWindowInputProvider(_surfaceService));
|
||||
_inputService.AddInputProvider(new NativeWindowInputProvider(_inputService));
|
||||
}
|
||||
|
||||
private void PluginServiceOnPluginEnabling(object sender, PluginEventArgs e)
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user