From 3553dcaa9958bdda414ebee7b6e7b2ddf1229a16 Mon Sep 17 00:00:00 2001 From: Daniel Belz Date: Fri, 13 Sep 2019 18:30:33 +0200 Subject: [PATCH 1/5] Added NeatInput dependency --- src/Kirei.Infrastructure/Kirei.Infrastructure.csproj | 1 + 1 file changed, 1 insertion(+) diff --git a/src/Kirei.Infrastructure/Kirei.Infrastructure.csproj b/src/Kirei.Infrastructure/Kirei.Infrastructure.csproj index 42f680d..7fdb6bf 100644 --- a/src/Kirei.Infrastructure/Kirei.Infrastructure.csproj +++ b/src/Kirei.Infrastructure/Kirei.Infrastructure.csproj @@ -16,6 +16,7 @@ + From 4bfeb9b3a771c46bd5b4a2453a012356678bd6d3 Mon Sep 17 00:00:00 2001 From: Daniel Belz Date: Fri, 13 Sep 2019 18:48:29 +0200 Subject: [PATCH 2/5] Added basic draft of the new implementation --- .../System/Input/InputListener.cs | 24 +++++++++++++++++-- 1 file changed, 22 insertions(+), 2 deletions(-) diff --git a/src/Kirei.Infrastructure/System/Input/InputListener.cs b/src/Kirei.Infrastructure/System/Input/InputListener.cs index 6aac851..1d9ccaf 100644 --- a/src/Kirei.Infrastructure/System/Input/InputListener.cs +++ b/src/Kirei.Infrastructure/System/Input/InputListener.cs @@ -2,6 +2,10 @@ using Kirei.Infrastructure.Configuration; using Kirei.Infrastructure.Native; +using NeatInput; + +using System; +using System.Diagnostics; using System.Threading; namespace Kirei.Infrastructure.System.Input @@ -9,18 +13,28 @@ namespace Kirei.Infrastructure.System.Input public class InputListener : IInputListener { + private InputProvider _inputProvider; private IInputActionMapper _inputActionMapper; - private bool hasIconsBeenHidden = false; + + private DateTime lastInputReceivedAt; + private bool hasIconsBeenHidden = false; public void Listen(IInputActionMapper inputActionMapper) { + _inputProvider = new InputProvider(); _inputActionMapper = inputActionMapper; + lastInputReceivedAt = DateTime.Now; + + _inputProvider.InputReceived += OnInputReceived; + while (true) { - var lastInputInMilliseconds = User32.GetUserIdleTime(); + var lastInputInMilliseconds = DateTime.Now.Subtract(lastInputReceivedAt).TotalMilliseconds; var inactiveAfterMs = ConfigurationProvider.Configuration.Application.InactiveAfterMs; + Debug.WriteLine(lastInputInMilliseconds); + if (lastInputInMilliseconds >= inactiveAfterMs && !hasIconsBeenHidden) { _inputActionMapper.HandleInput(); @@ -35,5 +49,11 @@ public void Listen(IInputActionMapper inputActionMapper) Thread.Sleep(ConfigurationProvider.Configuration.Application.InputPollingRate); } } + + private void OnInputReceived(NeatInput.Domain.Hooking.Input input) + { + Debug.WriteLine("INPUT"); + lastInputReceivedAt = DateTime.Now; + } } } From 95846d8d369efb0d5bd2f15929cce199eac65527 Mon Sep 17 00:00:00 2001 From: Daniel Belz Date: Fri, 13 Sep 2019 18:49:20 +0200 Subject: [PATCH 3/5] Removed GetLastInputInfo --- .../Native/User32.Wrappers.cs | 19 ------------------- 1 file changed, 19 deletions(-) diff --git a/src/Kirei.Infrastructure/Native/User32.Wrappers.cs b/src/Kirei.Infrastructure/Native/User32.Wrappers.cs index f69b84e..9cadc70 100644 --- a/src/Kirei.Infrastructure/Native/User32.Wrappers.cs +++ b/src/Kirei.Infrastructure/Native/User32.Wrappers.cs @@ -9,15 +9,6 @@ namespace Kirei.Infrastructure.Native { internal static partial class User32 { - internal struct LASTINPUTINFO - { - public uint cbSize; - public uint dwTime; - } - - [DllImport("user32.dll")] - private static extern bool GetLastInputInfo(ref LASTINPUTINFO plii); - [DllImport("user32.dll", CharSet = CharSet.Auto)] private static extern int GetClassName( IntPtr hWnd, @@ -39,16 +30,6 @@ SetWindowPosFlags uFlags private static extern bool GetWindowRect( IntPtr hwnd, ref RECT rectangle); - - internal static long GetUserIdleTime() - { - var lastInputStruct = new LASTINPUTINFO(); - lastInputStruct.cbSize = (uint)Marshal.SizeOf(lastInputStruct); - - GetLastInputInfo(ref lastInputStruct); - - return ((uint)Environment.TickCount - lastInputStruct.dwTime); - } internal static string GetClassName(IntPtr hWnd) { From 94dc7aa966c79a6e16bc3af085b715a01230f0bd Mon Sep 17 00:00:00 2001 From: Daniel Belz Date: Fri, 13 Sep 2019 18:51:05 +0200 Subject: [PATCH 4/5] Finished implementation --- .../System/Input/InputListener.cs | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) diff --git a/src/Kirei.Infrastructure/System/Input/InputListener.cs b/src/Kirei.Infrastructure/System/Input/InputListener.cs index 1d9ccaf..fcc3bb2 100644 --- a/src/Kirei.Infrastructure/System/Input/InputListener.cs +++ b/src/Kirei.Infrastructure/System/Input/InputListener.cs @@ -1,11 +1,9 @@ using Kirei.Application.System.Input; using Kirei.Infrastructure.Configuration; -using Kirei.Infrastructure.Native; using NeatInput; using System; -using System.Diagnostics; using System.Threading; namespace Kirei.Infrastructure.System.Input @@ -28,12 +26,12 @@ public void Listen(IInputActionMapper inputActionMapper) _inputProvider.InputReceived += OnInputReceived; + var inactiveAfterMs = ConfigurationProvider.Configuration.Application.InactiveAfterMs; + var inputPollingRateMs = ConfigurationProvider.Configuration.Application.InputPollingRate; + while (true) { - var lastInputInMilliseconds = DateTime.Now.Subtract(lastInputReceivedAt).TotalMilliseconds; - var inactiveAfterMs = ConfigurationProvider.Configuration.Application.InactiveAfterMs; - - Debug.WriteLine(lastInputInMilliseconds); + var lastInputInMilliseconds = DateTime.Now.Subtract(lastInputReceivedAt).TotalMilliseconds; if (lastInputInMilliseconds >= inactiveAfterMs && !hasIconsBeenHidden) { @@ -46,13 +44,12 @@ public void Listen(IInputActionMapper inputActionMapper) hasIconsBeenHidden = false; } - Thread.Sleep(ConfigurationProvider.Configuration.Application.InputPollingRate); + Thread.Sleep(inputPollingRateMs); } } private void OnInputReceived(NeatInput.Domain.Hooking.Input input) { - Debug.WriteLine("INPUT"); lastInputReceivedAt = DateTime.Now; } } From 476e8bc6a3e6c38b1d690c7f6cfbe02176cf66d0 Mon Sep 17 00:00:00 2001 From: Daniel Belz Date: Sun, 15 Sep 2019 15:16:49 +0200 Subject: [PATCH 5/5] Upgraded to NeatInput 1.0.1 and made namespace changes. --- .../{Input => InputProcessing}/IInputActionMapper.cs | 2 +- .../System/{Input => InputProcessing}/IInputListener.cs | 2 +- src/Kirei.Infrastructure/Kirei.Infrastructure.csproj | 2 +- .../System/{Input => InputProcessing}/InputActionMapper.cs | 4 ++-- .../System/{Input => InputProcessing}/InputListener.cs | 7 ++++--- src/Kirei/App.cs | 2 +- src/Kirei/Program.cs | 4 ++-- 7 files changed, 12 insertions(+), 11 deletions(-) rename src/Kirei.Application/System/{Input => InputProcessing}/IInputActionMapper.cs (76%) rename src/Kirei.Application/System/{Input => InputProcessing}/IInputListener.cs (71%) rename src/Kirei.Infrastructure/System/{Input => InputProcessing}/InputActionMapper.cs (86%) rename src/Kirei.Infrastructure/System/{Input => InputProcessing}/InputListener.cs (89%) diff --git a/src/Kirei.Application/System/Input/IInputActionMapper.cs b/src/Kirei.Application/System/InputProcessing/IInputActionMapper.cs similarity index 76% rename from src/Kirei.Application/System/Input/IInputActionMapper.cs rename to src/Kirei.Application/System/InputProcessing/IInputActionMapper.cs index 6d171b2..7c7625f 100644 --- a/src/Kirei.Application/System/Input/IInputActionMapper.cs +++ b/src/Kirei.Application/System/InputProcessing/IInputActionMapper.cs @@ -1,6 +1,6 @@ using System; -namespace Kirei.Application.System.Input +namespace Kirei.Application.System.InputProcessing { public interface IInputActionMapper { diff --git a/src/Kirei.Application/System/Input/IInputListener.cs b/src/Kirei.Application/System/InputProcessing/IInputListener.cs similarity index 71% rename from src/Kirei.Application/System/Input/IInputListener.cs rename to src/Kirei.Application/System/InputProcessing/IInputListener.cs index a9f75ed..592c9a5 100644 --- a/src/Kirei.Application/System/Input/IInputListener.cs +++ b/src/Kirei.Application/System/InputProcessing/IInputListener.cs @@ -1,6 +1,6 @@ using System; -namespace Kirei.Application.System.Input +namespace Kirei.Application.System.InputProcessing { public interface IInputListener { diff --git a/src/Kirei.Infrastructure/Kirei.Infrastructure.csproj b/src/Kirei.Infrastructure/Kirei.Infrastructure.csproj index 7fdb6bf..1d6f511 100644 --- a/src/Kirei.Infrastructure/Kirei.Infrastructure.csproj +++ b/src/Kirei.Infrastructure/Kirei.Infrastructure.csproj @@ -16,7 +16,7 @@ - + diff --git a/src/Kirei.Infrastructure/System/Input/InputActionMapper.cs b/src/Kirei.Infrastructure/System/InputProcessing/InputActionMapper.cs similarity index 86% rename from src/Kirei.Infrastructure/System/Input/InputActionMapper.cs rename to src/Kirei.Infrastructure/System/InputProcessing/InputActionMapper.cs index c1afe19..6ef98b4 100644 --- a/src/Kirei.Infrastructure/System/Input/InputActionMapper.cs +++ b/src/Kirei.Infrastructure/System/InputProcessing/InputActionMapper.cs @@ -1,9 +1,9 @@ -using Kirei.Application.System.Input; +using Kirei.Application.System.InputProcessing; using System; using System.Collections.Generic; -namespace Kirei.Infrastructure.System.Input +namespace Kirei.Infrastructure.System.InputProcessing { public class InputActionMapper : IInputActionMapper { diff --git a/src/Kirei.Infrastructure/System/Input/InputListener.cs b/src/Kirei.Infrastructure/System/InputProcessing/InputListener.cs similarity index 89% rename from src/Kirei.Infrastructure/System/Input/InputListener.cs rename to src/Kirei.Infrastructure/System/InputProcessing/InputListener.cs index fcc3bb2..26a803c 100644 --- a/src/Kirei.Infrastructure/System/Input/InputListener.cs +++ b/src/Kirei.Infrastructure/System/InputProcessing/InputListener.cs @@ -1,12 +1,13 @@ -using Kirei.Application.System.Input; +using Kirei.Application.System.InputProcessing; using Kirei.Infrastructure.Configuration; using NeatInput; +using NeatInput.Domain.Processing; using System; using System.Threading; -namespace Kirei.Infrastructure.System.Input +namespace Kirei.Infrastructure.System.InputProcessing { public class InputListener : IInputListener @@ -48,7 +49,7 @@ public void Listen(IInputActionMapper inputActionMapper) } } - private void OnInputReceived(NeatInput.Domain.Hooking.Input input) + private void OnInputReceived(Input input) { lastInputReceivedAt = DateTime.Now; } diff --git a/src/Kirei/App.cs b/src/Kirei/App.cs index 13af09a..1bda856 100644 --- a/src/Kirei/App.cs +++ b/src/Kirei/App.cs @@ -1,7 +1,7 @@ using Kirei.Application; using Kirei.Application.System; using Kirei.Application.System.Desktop; -using Kirei.Application.System.Input; +using Kirei.Application.System.InputProcessing; using Kirei.Infrastructure.Configuration; namespace Kirei diff --git a/src/Kirei/Program.cs b/src/Kirei/Program.cs index d773972..9e25cf7 100644 --- a/src/Kirei/Program.cs +++ b/src/Kirei/Program.cs @@ -1,11 +1,11 @@ using Kirei.Application; using Kirei.Application.System; using Kirei.Application.System.Desktop; -using Kirei.Application.System.Input; +using Kirei.Application.System.InputProcessing; using Kirei.Infrastructure; using Kirei.Infrastructure.System; using Kirei.Infrastructure.System.Desktop; -using Kirei.Infrastructure.System.Input; +using Kirei.Infrastructure.System.InputProcessing; using Microsoft.Extensions.DependencyInjection;