using System; using System.Collections.Generic; using System.Text; using System.Runtime.InteropServices; using System.Windows.Forms; namespace Salamax { public static class KeyboardInfo { public static bool KeysEnabled = false; static KeyboardInfo() { } [DllImport("user32")] private static extern short GetKeyState(int vKey); public static KeyStateInfo GetKeyState(Keys key) { short keyState = GetKeyState((int)key); byte[] bits = BitConverter.GetBytes(keyState); bool toggled = bits[0] > 0, pressed = bits[1] > 0; return new KeyStateInfo(key, KeysEnabled ? pressed : false, toggled); } } public struct KeyStateInfo { Keys _key; bool _isPressed, _isToggled; public KeyStateInfo(Keys key, bool ispressed, bool istoggled) { _key = key; _isPressed = ispressed; _isToggled = istoggled; } public static KeyStateInfo Default { get { return new KeyStateInfo(Keys.None, false, false); } } public Keys Key { get { return _key; } } public bool IsPressed { get { return _isPressed; } } public bool IsToggled { get { return _isToggled; } } } }