This commit is contained in:
2025-01-06 23:31:47 +03:00
parent d3b899ba93
commit 2061eb9347
14 changed files with 114 additions and 255718 deletions

View File

@@ -1,10 +1,13 @@
using Engine.Input;
using System.Globalization;
using Engine.Input;
using OpenTK.Mathematics;
namespace PresenterConsole;
public class ConsoleInputHandler : IInputHandler
{
public CultureInfo CurrentInputLanguage => WindowsFFI.GetCurrentKeyboardLayout();
public Vector2 MousePosition => Vector2.Zero;
private readonly bool[] _currentKeys = new bool[256];

View File

@@ -1,4 +1,5 @@
using System.Runtime.CompilerServices;
using System.Globalization;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Runtime.InteropServices.Marshalling;
using Microsoft.Win32.SafeHandles;
@@ -67,4 +68,28 @@ public static partial class WindowsFFI
[LibraryImport("user32.dll", SetLastError = true, EntryPoint = "GetAsyncKeyState")]
public static partial short GetAsyncKeyState(int parKeyCode);
[LibraryImport("user32.dll", SetLastError = true, EntryPoint = "GetForegroundWindow")]
public static partial IntPtr GetForegroundWindow();
[LibraryImport("user32.dll", SetLastError = true, EntryPoint = "GetWindowThreadProcessId")]
public static partial uint GetWindowThreadProcessId(IntPtr parHwnd, IntPtr parLpdwProcessId);
[LibraryImport("user32.dll", SetLastError = true, EntryPoint = "GetKeyboardLayout")]
public static partial IntPtr GetKeyboardLayout(uint parThreadId);
public static CultureInfo GetCurrentKeyboardLayout()
{
try
{
IntPtr foregroundWindow = GetForegroundWindow();
uint foregroundProcess = GetWindowThreadProcessId(foregroundWindow, IntPtr.Zero);
int keyboardLayout = GetKeyboardLayout(foregroundProcess).ToInt32() & 0xFFFF;
return new CultureInfo(keyboardLayout);
}
catch (Exception _)
{
return new CultureInfo(1033); // Assume English if something went wrong.
}
}
}