This repository has been archived on 2022-08-05. You can view files and clone it, but cannot push or open issues or pull requests.
CC-Functions/W32/KeyboardReader.cs

29 lines
752 B
C#
Raw Normal View History

2019-11-29 21:27:24 +01:00
using System.Runtime.InteropServices;
2019-10-05 17:52:14 +02:00
using System.Windows.Forms;
namespace CC_Functions.W32
{
public static class KeyboardReader
{
[DllImport("user32.dll", CharSet = CharSet.Auto, ExactSpelling = true)]
2019-11-29 21:27:24 +01:00
private static extern short GetKeyState(int keyCode);
2019-10-05 17:52:14 +02:00
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;
2019-11-10 12:28:29 +01:00
return (state & 1) == 1;
2019-10-05 17:52:14 +02:00
}
catch
{
throw;
}
}
}
2019-11-29 21:27:24 +01:00
}