Skip to content

Commit 8355280

Browse files
author
LegendaryB
authored
Merge pull request #28 from LegendaryB/develop
Release v1.4
2 parents f00a3c9 + 1dd9c5a commit 8355280

File tree

9 files changed

+65
-65
lines changed

9 files changed

+65
-65
lines changed

src/Kirei.Application/System/Input/IInputActionMapper.cs src/Kirei.Application/System/InputProcessing/IInputActionMapper.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
using System;
22

3-
namespace Kirei.Application.System.Input
3+
namespace Kirei.Application.System.InputProcessing
44
{
55
public interface IInputActionMapper
66
{

src/Kirei.Application/System/Input/IInputListener.cs src/Kirei.Application/System/InputProcessing/IInputListener.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
using System;
22

3-
namespace Kirei.Application.System.Input
3+
namespace Kirei.Application.System.InputProcessing
44
{
55
public interface IInputListener
66
{

src/Kirei.Infrastructure/Kirei.Infrastructure.csproj

+1
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
<PackageReference Include="Microsoft.Extensions.Configuration.FileExtensions" Version="2.2.0" />
1717
<PackageReference Include="Microsoft.Extensions.Configuration.Json" Version="2.2.0" />
1818
<PackageReference Include="Microsoft.Win32.Registry" Version="4.5.0" />
19+
<PackageReference Include="NeatInput" Version="1.0.1" />
1920
</ItemGroup>
2021

2122
<ItemGroup>

src/Kirei.Infrastructure/Native/User32.Wrappers.cs

-19
Original file line numberDiff line numberDiff line change
@@ -9,15 +9,6 @@ namespace Kirei.Infrastructure.Native
99
{
1010
internal static partial class User32
1111
{
12-
internal struct LASTINPUTINFO
13-
{
14-
public uint cbSize;
15-
public uint dwTime;
16-
}
17-
18-
[DllImport("user32.dll")]
19-
private static extern bool GetLastInputInfo(ref LASTINPUTINFO plii);
20-
2112
[DllImport("user32.dll", CharSet = CharSet.Auto)]
2213
private static extern int GetClassName(
2314
IntPtr hWnd,
@@ -39,16 +30,6 @@ SetWindowPosFlags uFlags
3930
private static extern bool GetWindowRect(
4031
IntPtr hwnd,
4132
ref RECT rectangle);
42-
43-
internal static long GetUserIdleTime()
44-
{
45-
var lastInputStruct = new LASTINPUTINFO();
46-
lastInputStruct.cbSize = (uint)Marshal.SizeOf(lastInputStruct);
47-
48-
GetLastInputInfo(ref lastInputStruct);
49-
50-
return ((uint)Environment.TickCount - lastInputStruct.dwTime);
51-
}
5233

5334
internal static string GetClassName(IntPtr hWnd)
5435
{

src/Kirei.Infrastructure/System/Input/InputListener.cs

-39
This file was deleted.

src/Kirei.Infrastructure/System/Input/InputActionMapper.cs src/Kirei.Infrastructure/System/InputProcessing/InputActionMapper.cs

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
using Kirei.Application.System.Input;
1+
using Kirei.Application.System.InputProcessing;
22

33
using System;
44
using System.Collections.Generic;
55

6-
namespace Kirei.Infrastructure.System.Input
6+
namespace Kirei.Infrastructure.System.InputProcessing
77
{
88
public class InputActionMapper : IInputActionMapper
99
{
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
using Kirei.Application.System.InputProcessing;
2+
using Kirei.Infrastructure.Configuration;
3+
4+
using NeatInput;
5+
using NeatInput.Domain.Processing;
6+
7+
using System;
8+
using System.Threading;
9+
10+
namespace Kirei.Infrastructure.System.InputProcessing
11+
{
12+
public class InputListener :
13+
IInputListener
14+
{
15+
private InputProvider _inputProvider;
16+
private IInputActionMapper _inputActionMapper;
17+
18+
private DateTime lastInputReceivedAt;
19+
private bool hasIconsBeenHidden = false;
20+
21+
public void Listen(IInputActionMapper inputActionMapper)
22+
{
23+
_inputProvider = new InputProvider();
24+
_inputActionMapper = inputActionMapper;
25+
26+
lastInputReceivedAt = DateTime.Now;
27+
28+
_inputProvider.InputReceived += OnInputReceived;
29+
30+
var inactiveAfterMs = ConfigurationProvider.Configuration.Application.InactiveAfterMs;
31+
var inputPollingRateMs = ConfigurationProvider.Configuration.Application.InputPollingRate;
32+
33+
while (true)
34+
{
35+
var lastInputInMilliseconds = DateTime.Now.Subtract(lastInputReceivedAt).TotalMilliseconds;
36+
37+
if (lastInputInMilliseconds >= inactiveAfterMs && !hasIconsBeenHidden)
38+
{
39+
_inputActionMapper.HandleInput();
40+
hasIconsBeenHidden = true;
41+
}
42+
else if (lastInputInMilliseconds < inactiveAfterMs && hasIconsBeenHidden)
43+
{
44+
_inputActionMapper.HandleInput();
45+
hasIconsBeenHidden = false;
46+
}
47+
48+
Thread.Sleep(inputPollingRateMs);
49+
}
50+
}
51+
52+
private void OnInputReceived(Input input)
53+
{
54+
lastInputReceivedAt = DateTime.Now;
55+
}
56+
}
57+
}

src/Kirei/App.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
using Kirei.Application;
22
using Kirei.Application.System;
33
using Kirei.Application.System.Desktop;
4-
using Kirei.Application.System.Input;
4+
using Kirei.Application.System.InputProcessing;
55
using Kirei.Infrastructure.Configuration;
66

77
namespace Kirei

src/Kirei/Program.cs

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
using Kirei.Application;
22
using Kirei.Application.System;
33
using Kirei.Application.System.Desktop;
4-
using Kirei.Application.System.Input;
4+
using Kirei.Application.System.InputProcessing;
55
using Kirei.Infrastructure;
66
using Kirei.Infrastructure.System;
77
using Kirei.Infrastructure.System.Desktop;
8-
using Kirei.Infrastructure.System.Input;
8+
using Kirei.Infrastructure.System.InputProcessing;
99

1010
using Microsoft.Extensions.DependencyInjection;
1111

0 commit comments

Comments
 (0)