mirror of
https://github.com/Artemis-RGB/Artemis
synced 2025-12-13 05:48:35 +00:00
Merge remote-tracking branch 'origin/master'
This commit is contained in:
commit
051d981a01
@ -21,7 +21,7 @@ namespace Artemis.Core.Services
|
|||||||
public ArtemisDevice? Device { get; }
|
public ArtemisDevice? Device { get; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Gets the LED that corresponds to the pressed key
|
/// Gets the LED that corresponds to the pressed key
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public ArtemisLed? Led { get; }
|
public ArtemisLed? Led { get; }
|
||||||
|
|
||||||
|
|||||||
@ -0,0 +1,26 @@
|
|||||||
|
using System;
|
||||||
|
|
||||||
|
namespace Artemis.Core.Services
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Contains data for keyboard input events
|
||||||
|
/// </summary>
|
||||||
|
public class ArtemisKeyboardToggleStatusArgs : EventArgs
|
||||||
|
{
|
||||||
|
internal ArtemisKeyboardToggleStatusArgs(KeyboardToggleStatus oldStatus, KeyboardToggleStatus newStatus)
|
||||||
|
{
|
||||||
|
OldStatus = oldStatus;
|
||||||
|
NewStatus = newStatus;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets the keyboard status before the change
|
||||||
|
/// </summary>
|
||||||
|
public KeyboardToggleStatus OldStatus { get; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets the keyboard status after the change
|
||||||
|
/// </summary>
|
||||||
|
public KeyboardToggleStatus NewStatus { get; }
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -8,6 +8,7 @@ namespace Artemis.Core.Services
|
|||||||
public class InputProviderKeyboardEventArgs : EventArgs
|
public class InputProviderKeyboardEventArgs : EventArgs
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
/// Creates a new instance of the <see cref="InputProviderKeyboardEventArgs " /> class
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="device">The device that triggered the event</param>
|
/// <param name="device">The device that triggered the event</param>
|
||||||
/// <param name="key">The key that triggered the event</param>
|
/// <param name="key">The key that triggered the event</param>
|
||||||
|
|||||||
@ -0,0 +1,24 @@
|
|||||||
|
using System;
|
||||||
|
|
||||||
|
namespace Artemis.Core.Services
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Contains data for input provider keyboard status toggle events
|
||||||
|
/// </summary>
|
||||||
|
public class InputProviderKeyboardToggleEventArgs : EventArgs
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Creates a new instance of the <see cref="InputProviderKeyboardToggleEventArgs " /> class
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="keyboardToggleStatus">The toggle status of the keyboard</param>
|
||||||
|
public InputProviderKeyboardToggleEventArgs(KeyboardToggleStatus keyboardToggleStatus)
|
||||||
|
{
|
||||||
|
KeyboardToggleStatus = keyboardToggleStatus;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets the toggle status of the keyboard
|
||||||
|
/// </summary>
|
||||||
|
public KeyboardToggleStatus KeyboardToggleStatus { get; }
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -8,11 +8,23 @@ namespace Artemis.Core.Services
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
public abstract class InputProvider : IDisposable
|
public abstract class InputProvider : IDisposable
|
||||||
{
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Called when the input service requests a <see cref="KeyboardToggleStatusReceived"/> event
|
||||||
|
/// </summary>
|
||||||
|
public virtual void OnKeyboardToggleStatusRequested()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Occurs when the input provided has received keyboard data
|
/// Occurs when the input provided has received keyboard data
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public event EventHandler<InputProviderKeyboardEventArgs>? KeyboardDataReceived;
|
public event EventHandler<InputProviderKeyboardEventArgs>? KeyboardDataReceived;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Occurs when the input provider has received new toggle data for keyboards
|
||||||
|
/// </summary>
|
||||||
|
public event EventHandler<InputProviderKeyboardToggleEventArgs>? KeyboardToggleStatusReceived;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Occurs when the input provided has received mouse button data
|
/// Occurs when the input provided has received mouse button data
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@ -95,6 +107,17 @@ namespace Artemis.Core.Services
|
|||||||
IdentifierReceived?.Invoke(this, new InputProviderIdentifierEventArgs(identifier, deviceType));
|
IdentifierReceived?.Invoke(this, new InputProviderIdentifierEventArgs(identifier, deviceType));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Invokes the <see cref="KeyboardToggleStatusReceived" /> event which the <see cref="IInputService" /> listens to as
|
||||||
|
/// long as
|
||||||
|
/// this provider is registered
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="keyboardToggleStatus">The toggle status of the keyboard</param>
|
||||||
|
protected virtual void OnKeyboardToggleStatusReceived(KeyboardToggleStatus keyboardToggleStatus)
|
||||||
|
{
|
||||||
|
KeyboardToggleStatusReceived?.Invoke(this, new InputProviderKeyboardToggleEventArgs(keyboardToggleStatus));
|
||||||
|
}
|
||||||
|
|
||||||
#region IDisposable
|
#region IDisposable
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
|||||||
@ -36,16 +36,22 @@ namespace Artemis.Core.Services
|
|||||||
|
|
||||||
private readonly List<InputProvider> _inputProviders = new();
|
private readonly List<InputProvider> _inputProviders = new();
|
||||||
|
|
||||||
|
public KeyboardToggleStatus KeyboardToggleStatus { get; private set; } = new(false, false, false);
|
||||||
|
|
||||||
public void AddInputProvider(InputProvider inputProvider)
|
public void AddInputProvider(InputProvider inputProvider)
|
||||||
{
|
{
|
||||||
inputProvider.IdentifierReceived += InputProviderOnIdentifierReceived;
|
inputProvider.IdentifierReceived += InputProviderOnIdentifierReceived;
|
||||||
inputProvider.KeyboardDataReceived += InputProviderOnKeyboardDataReceived;
|
inputProvider.KeyboardDataReceived += InputProviderOnKeyboardDataReceived;
|
||||||
|
inputProvider.KeyboardToggleStatusReceived += InputProviderOnKeyboardToggleStatusReceived;
|
||||||
inputProvider.MouseButtonDataReceived += InputProviderOnMouseButtonDataReceived;
|
inputProvider.MouseButtonDataReceived += InputProviderOnMouseButtonDataReceived;
|
||||||
inputProvider.MouseScrollDataReceived += InputProviderOnMouseScrollDataReceived;
|
inputProvider.MouseScrollDataReceived += InputProviderOnMouseScrollDataReceived;
|
||||||
inputProvider.MouseMoveDataReceived += InputProviderOnMouseMoveDataReceived;
|
inputProvider.MouseMoveDataReceived += InputProviderOnMouseMoveDataReceived;
|
||||||
_inputProviders.Add(inputProvider);
|
_inputProviders.Add(inputProvider);
|
||||||
|
|
||||||
|
inputProvider.OnKeyboardToggleStatusRequested();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public void RemoveInputProvider(InputProvider inputProvider)
|
public void RemoveInputProvider(InputProvider inputProvider)
|
||||||
{
|
{
|
||||||
if (!_inputProviders.Contains(inputProvider))
|
if (!_inputProviders.Contains(inputProvider))
|
||||||
@ -54,6 +60,7 @@ namespace Artemis.Core.Services
|
|||||||
_inputProviders.Remove(inputProvider);
|
_inputProviders.Remove(inputProvider);
|
||||||
inputProvider.IdentifierReceived -= InputProviderOnIdentifierReceived;
|
inputProvider.IdentifierReceived -= InputProviderOnIdentifierReceived;
|
||||||
inputProvider.KeyboardDataReceived -= InputProviderOnKeyboardDataReceived;
|
inputProvider.KeyboardDataReceived -= InputProviderOnKeyboardDataReceived;
|
||||||
|
inputProvider.KeyboardToggleStatusReceived -= InputProviderOnKeyboardToggleStatusReceived;
|
||||||
inputProvider.MouseButtonDataReceived -= InputProviderOnMouseButtonDataReceived;
|
inputProvider.MouseButtonDataReceived -= InputProviderOnMouseButtonDataReceived;
|
||||||
inputProvider.MouseScrollDataReceived -= InputProviderOnMouseScrollDataReceived;
|
inputProvider.MouseScrollDataReceived -= InputProviderOnMouseScrollDataReceived;
|
||||||
inputProvider.MouseMoveDataReceived -= InputProviderOnMouseMoveDataReceived;
|
inputProvider.MouseMoveDataReceived -= InputProviderOnMouseMoveDataReceived;
|
||||||
@ -209,6 +216,18 @@ namespace Artemis.Core.Services
|
|||||||
// _logger.Verbose("Keyboard data: LED ID: {ledId}, key: {key}, is down: {isDown}, modifiers: {modifiers}, device: {device} ", ledId, e.Key, e.IsDown, keyboardModifierKey, e.Device);
|
// _logger.Verbose("Keyboard data: LED ID: {ledId}, key: {key}, is down: {isDown}, modifiers: {modifiers}, device: {device} ", ledId, e.Key, e.IsDown, keyboardModifierKey, e.Device);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void InputProviderOnKeyboardToggleStatusReceived(object? sender, InputProviderKeyboardToggleEventArgs e)
|
||||||
|
{
|
||||||
|
KeyboardToggleStatus old = KeyboardToggleStatus;
|
||||||
|
if (KeyboardToggleStatus.CapsLock == e.KeyboardToggleStatus.CapsLock &&
|
||||||
|
KeyboardToggleStatus.NumLock == e.KeyboardToggleStatus.NumLock &&
|
||||||
|
KeyboardToggleStatus.ScrollLock == e.KeyboardToggleStatus.ScrollLock)
|
||||||
|
return;
|
||||||
|
|
||||||
|
KeyboardToggleStatus = e.KeyboardToggleStatus;
|
||||||
|
OnKeyboardToggleStatusChanged(new ArtemisKeyboardToggleStatusArgs(old, KeyboardToggleStatus));
|
||||||
|
}
|
||||||
|
|
||||||
private bool UpdatePressedKeys(ArtemisDevice? device, KeyboardKey key, bool isDown)
|
private bool UpdatePressedKeys(ArtemisDevice? device, KeyboardKey key, bool isDown)
|
||||||
{
|
{
|
||||||
if (device != null)
|
if (device != null)
|
||||||
@ -318,6 +337,8 @@ namespace Artemis.Core.Services
|
|||||||
public event EventHandler<ArtemisKeyboardKeyUpDownEventArgs>? KeyboardKeyUpDown;
|
public event EventHandler<ArtemisKeyboardKeyUpDownEventArgs>? KeyboardKeyUpDown;
|
||||||
public event EventHandler<ArtemisKeyboardKeyEventArgs>? KeyboardKeyDown;
|
public event EventHandler<ArtemisKeyboardKeyEventArgs>? KeyboardKeyDown;
|
||||||
public event EventHandler<ArtemisKeyboardKeyEventArgs>? KeyboardKeyUp;
|
public event EventHandler<ArtemisKeyboardKeyEventArgs>? KeyboardKeyUp;
|
||||||
|
public event EventHandler<ArtemisKeyboardToggleStatusArgs>? KeyboardToggleStatusChanged;
|
||||||
|
|
||||||
public event EventHandler<ArtemisMouseButtonUpDownEventArgs>? MouseButtonUpDown;
|
public event EventHandler<ArtemisMouseButtonUpDownEventArgs>? MouseButtonUpDown;
|
||||||
public event EventHandler<ArtemisMouseButtonEventArgs>? MouseButtonDown;
|
public event EventHandler<ArtemisMouseButtonEventArgs>? MouseButtonDown;
|
||||||
public event EventHandler<ArtemisMouseButtonEventArgs>? MouseButtonUp;
|
public event EventHandler<ArtemisMouseButtonEventArgs>? MouseButtonUp;
|
||||||
@ -340,6 +361,11 @@ namespace Artemis.Core.Services
|
|||||||
KeyboardKeyUp?.Invoke(this, e);
|
KeyboardKeyUp?.Invoke(this, e);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected virtual void OnKeyboardToggleStatusChanged(ArtemisKeyboardToggleStatusArgs e)
|
||||||
|
{
|
||||||
|
KeyboardToggleStatusChanged?.Invoke(this, e);
|
||||||
|
}
|
||||||
|
|
||||||
protected virtual void OnMouseButtonUpDown(ArtemisMouseButtonUpDownEventArgs e)
|
protected virtual void OnMouseButtonUpDown(ArtemisMouseButtonUpDownEventArgs e)
|
||||||
{
|
{
|
||||||
MouseButtonUpDown?.Invoke(this, e);
|
MouseButtonUpDown?.Invoke(this, e);
|
||||||
|
|||||||
@ -7,6 +7,11 @@ namespace Artemis.Core.Services
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
public interface IInputService : IArtemisService, IDisposable
|
public interface IInputService : IArtemisService, IDisposable
|
||||||
{
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Gets the current keyboard toggle status
|
||||||
|
/// </summary>
|
||||||
|
KeyboardToggleStatus KeyboardToggleStatus { get; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Adds an input provided
|
/// Adds an input provided
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@ -47,6 +52,11 @@ namespace Artemis.Core.Services
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
event EventHandler<ArtemisKeyboardKeyEventArgs> KeyboardKeyUp;
|
event EventHandler<ArtemisKeyboardKeyEventArgs> KeyboardKeyUp;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Occurs whenever a one or more of the keyboard toggle statuses changed
|
||||||
|
/// </summary>
|
||||||
|
event EventHandler<ArtemisKeyboardToggleStatusArgs> KeyboardToggleStatusChanged;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Occurs whenever a button on a mouse was pressed or released
|
/// Occurs whenever a button on a mouse was pressed or released
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
|||||||
36
src/Artemis.Core/Services/Input/KeyboardToggleStatus.cs
Normal file
36
src/Artemis.Core/Services/Input/KeyboardToggleStatus.cs
Normal file
@ -0,0 +1,36 @@
|
|||||||
|
namespace Artemis.Core.Services
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Represents the status of a keyboards special toggles
|
||||||
|
/// </summary>
|
||||||
|
public readonly struct KeyboardToggleStatus
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Creates a new <see cref="KeyboardToggleStatus" />
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="numLock">A boolean indicating whether num lock is on</param>
|
||||||
|
/// <param name="capsLock">A boolean indicating whether caps lock is on</param>
|
||||||
|
/// <param name="scrollLock">A boolean indicating whether scroll lock is on</param>
|
||||||
|
public KeyboardToggleStatus(bool numLock, bool capsLock, bool scrollLock)
|
||||||
|
{
|
||||||
|
NumLock = numLock;
|
||||||
|
CapsLock = capsLock;
|
||||||
|
ScrollLock = scrollLock;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets a boolean indicating whether num lock is on
|
||||||
|
/// </summary>
|
||||||
|
public bool NumLock { get; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets a boolean indicating whether caps lock is on
|
||||||
|
/// </summary>
|
||||||
|
public bool CapsLock { get; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets a boolean indicating whether scroll lock is on
|
||||||
|
/// </summary>
|
||||||
|
public bool ScrollLock { get; }
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -14,9 +14,9 @@ namespace Artemis.UI.InputProviders
|
|||||||
public class NativeWindowInputProvider : InputProvider
|
public class NativeWindowInputProvider : InputProvider
|
||||||
{
|
{
|
||||||
private const int WM_INPUT = 0x00FF;
|
private const int WM_INPUT = 0x00FF;
|
||||||
|
private readonly IInputService _inputService;
|
||||||
|
|
||||||
private readonly ILogger _logger;
|
private readonly ILogger _logger;
|
||||||
private readonly IInputService _inputService;
|
|
||||||
private DateTime _lastMouseUpdate;
|
private DateTime _lastMouseUpdate;
|
||||||
private SpongeWindow _sponge;
|
private SpongeWindow _sponge;
|
||||||
|
|
||||||
@ -32,6 +32,16 @@ namespace Artemis.UI.InputProviders
|
|||||||
RawInputDevice.RegisterDevice(HidUsageAndPage.Mouse, RawInputDeviceFlags.InputSink, _sponge.Handle);
|
RawInputDevice.RegisterDevice(HidUsageAndPage.Mouse, RawInputDeviceFlags.InputSink, _sponge.Handle);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#region Overrides of InputProvider
|
||||||
|
|
||||||
|
/// <inheritdoc />
|
||||||
|
public override void OnKeyboardToggleStatusRequested()
|
||||||
|
{
|
||||||
|
UpdateToggleStatus();
|
||||||
|
}
|
||||||
|
|
||||||
|
#endregion
|
||||||
|
|
||||||
#region IDisposable
|
#region IDisposable
|
||||||
|
|
||||||
/// <inheritdoc />
|
/// <inheritdoc />
|
||||||
@ -88,7 +98,6 @@ namespace Artemis.UI.InputProviders
|
|||||||
|
|
||||||
ArtemisDevice device = null;
|
ArtemisDevice device = null;
|
||||||
if (identifier != null)
|
if (identifier != null)
|
||||||
{
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
device = _inputService.GetDeviceByIdentifier(this, identifier, InputDeviceType.Keyboard);
|
device = _inputService.GetDeviceByIdentifier(this, identifier, InputDeviceType.Keyboard);
|
||||||
@ -97,7 +106,6 @@ namespace Artemis.UI.InputProviders
|
|||||||
{
|
{
|
||||||
_logger.Warning(e, "Failed to retrieve input device by its identifier");
|
_logger.Warning(e, "Failed to retrieve input device by its identifier");
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
// 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)
|
// 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 (keyboardData.Keyboard.Flags == RawKeyboardFlags.LeftKey || keyboardData.Keyboard.Flags == (RawKeyboardFlags.LeftKey | RawKeyboardFlags.Up))
|
if (keyboardData.Keyboard.Flags == RawKeyboardFlags.LeftKey || keyboardData.Keyboard.Flags == (RawKeyboardFlags.LeftKey | RawKeyboardFlags.Up))
|
||||||
@ -118,6 +126,16 @@ namespace Artemis.UI.InputProviders
|
|||||||
keyboardData.Keyboard.Flags != (RawKeyboardFlags.Up | RawKeyboardFlags.RightKey);
|
keyboardData.Keyboard.Flags != (RawKeyboardFlags.Up | RawKeyboardFlags.RightKey);
|
||||||
|
|
||||||
OnKeyboardDataReceived(device, key, isDown);
|
OnKeyboardDataReceived(device, key, isDown);
|
||||||
|
UpdateToggleStatus();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void UpdateToggleStatus()
|
||||||
|
{
|
||||||
|
OnKeyboardToggleStatusReceived(new KeyboardToggleStatus(
|
||||||
|
Keyboard.IsKeyToggled(Key.NumLock),
|
||||||
|
Keyboard.IsKeyToggled(Key.CapsLock),
|
||||||
|
Keyboard.IsKeyToggled(Key.Scroll)
|
||||||
|
));
|
||||||
}
|
}
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
@ -142,7 +160,6 @@ namespace Artemis.UI.InputProviders
|
|||||||
ArtemisDevice device = null;
|
ArtemisDevice device = null;
|
||||||
string identifier = data.Device?.DevicePath;
|
string identifier = data.Device?.DevicePath;
|
||||||
if (identifier != null)
|
if (identifier != null)
|
||||||
{
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
device = _inputService.GetDeviceByIdentifier(this, identifier, InputDeviceType.Keyboard);
|
device = _inputService.GetDeviceByIdentifier(this, identifier, InputDeviceType.Keyboard);
|
||||||
@ -151,7 +168,6 @@ namespace Artemis.UI.InputProviders
|
|||||||
{
|
{
|
||||||
_logger.Warning(e, "Failed to retrieve input device by its identifier");
|
_logger.Warning(e, "Failed to retrieve input device by its identifier");
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
// Debug.WriteLine($"Buttons: {data.Mouse.Buttons}, Data: {data.Mouse.ButtonData}, Flags: {data.Mouse.Flags}, XY: {data.Mouse.LastX},{data.Mouse.LastY}");
|
// Debug.WriteLine($"Buttons: {data.Mouse.Buttons}, Data: {data.Mouse.ButtonData}, Flags: {data.Mouse.Flags}, XY: {data.Mouse.LastX},{data.Mouse.LastY}");
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user