From 01abd93de8a1f463878770d0e1df9b6c88b44b0c Mon Sep 17 00:00:00 2001 From: CreepyCrafter24 <33260128+CreepyCrafter24@users.noreply.github.com> Date: Sat, 5 Oct 2019 17:52:14 +0200 Subject: [PATCH] Added Input class --- W32/KeyboardReader.cs | 33 +++++++++++++++++++++++++++++++++ W32/W32.csproj | 1 + 2 files changed, 34 insertions(+) create mode 100644 W32/KeyboardReader.cs diff --git a/W32/KeyboardReader.cs b/W32/KeyboardReader.cs new file mode 100644 index 0000000..924ebd0 --- /dev/null +++ b/W32/KeyboardReader.cs @@ -0,0 +1,33 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Runtime.InteropServices; +using System.Text; +using System.Threading.Tasks; +using System.Windows.Forms; + +namespace CC_Functions.W32 +{ + public static class KeyboardReader + { + [DllImport("user32.dll", CharSet = CharSet.Auto, ExactSpelling = true)] + static extern short GetKeyState(int keyCode); + public static bool IsKeyDown(Keys key) + { + try + { + int state = 0; + short retVal = GetKeyState((int)key); + if ((retVal & 0x8000) == 0x8000) + state |= 1; + if ((retVal & 1) == 1) + state |= 2; + return 1 == (state & 1); + } + catch + { + throw; + } + } + } +} diff --git a/W32/W32.csproj b/W32/W32.csproj index fe8ab9e..3e17c10 100644 --- a/W32/W32.csproj +++ b/W32/W32.csproj @@ -46,6 +46,7 @@ +