using System;
using System.Runtime.InteropServices;
namespace Hook2
{
public class KB
{
// Constructors
public KB()
{
}
// Methods
[DllImport("user32.dll")]
private extern static short GetKeyState(int nVirtKey);
[DllImport("user32.dll")]
private extern static void keybd_event(byte bVk, byte bScan, uint dwFlags, uint dwExtraInfo);
[DllImport("user32.dll")]
private extern static long SendMessage(int hwnd, long wMsg, long wParam, long lParam);
[DllImport("user32.dll")]
static extern void BlockInput(bool Block);
public static void SendKey(KB.VirtualKeys Key)
{
KB.keybd_event((byte)Key, 0x45, 1, uint.MinValue);
KB.Stop(Key);
}
public static void SendKey(char Key)
{
KB.keybd_event(0x41, 0x20, 1, uint.MinValue);
KB.Stop(Key);
}
public static void Stop(char Key)
{
KB.keybd_event((byte)Key, 0x45, 3, uint.MinValue);
}
public static void Stop(KB.VirtualKeys Key)
{
KB.keybd_event((byte)Key, 0x45, 3, uint.MinValue);
}
// Constants
private const uint KEYEVENTF_EXTENDEDKEY = 1;
private const uint KEYEVENTF_KEYUP = 2;
// Nested Types
public enum VirtualKeys : byte
{
VK_NUMLOCK = 0x90,
VK_SCROLL = 0x91,
VK_A = 0x3e,
VK_LBUTTON = 1,
VK_RBUTTON = 2,
VK_CANCEL = 3,
VK_MBUTTON = 4,
VK_BACK = 8,
VK_TAB = 9,
VK_CLEAR = 12,
VK_RETURN = 13,
VK_SHIFT = 0x10,
VK_CONTROL = 0x11,
VK_MENU = 0x12,
VK_PAUSE = 0x13,
VK_CAPITAL = 0x14,
VK_ESCAPE = 0x1b,
VK_SPACE = 0x20,
VK_PRIOR = 0x21,
VK_NEXT = 0x22,
VK_END = 0x23,
VK_HOME = 0x24,
VK_LEFT = 0x25,
VK_UP = 0x26,
VK_RIGHT = 0x27,
VK_DOWN = 0x28,
VK_SNAPSHOT = 0x2c,
VK_INSERT = 0x2d,
VK_DELETE = 0x2e,
Key_0 = 0x30,
Key_1 = 0x31,
Key_2 = 0x32,
Key_3 = 0x33,
Key_4 = 0x34,
Key_5 = 0x35,
Key_6 = 0x36,
Key_7 = 0x37,
Key_8 = 0x38,
Key_9 = 0x39,
Key_A = 0x41,
Key_B = 0x42,
Key_C = 0x43,
Key_D = 0x44,
Key_E = 0x45,
Key_F = 0x46,
Key_G = 0x47,
Key_H = 0x48,
Key_I = 0x49,
Key_J = 0x4a,
Key_K = 0x4b,
Key_L = 0x4c,
Key_M = 0x4d,
Key_N = 0x4e,
Key_O = 0x4f,
Key_P = 0x50,
Key_Q = 0x51,
Key_R = 0x52,
Key_S = 0x53,
Key_T = 0x54,
Key_U = 0x55,
Key_V = 0x56,
Key_W = 0x57,
Key_X = 0x58,
Key_Y = 0x59,
Key_Z = 0x5a,
VK_DIVIDE = 0x6f,
VK_F1 = 0x70,
VK_F2 = 0x71,
VK_F3 = 0x72,
VK_F4 = 0x73,
VK_F5 = 0x74,
VK_F6 = 0x75,
VK_F7 = 0x76,
VK_F8 = 0x77,
VK_F9 = 0x78,
VK_F10 = 0x79,
VK_F11 = 0x7a,
VK_F12 = 0x7b
}
public static void BlockKeyBoardInput(bool flag)
{
BlockInput(flag);
}
}
}