private static extern UInt32 SendInput(UInt32 nInputs, ref INPUT pInputs, int cbSize);
 public static void KeybdEvent(byte key, byte bScan, KeybdEventFlag flags, uint dwExtraInfo)
 {     
     INPUT input = new INPUT();            
     input.type = 1; //keyboard
     input.ki.wVk = key;
     input.ki.wScan = MapVirtualKey(key, 0); 
     input.ki.dwFlags = (int)flags;
     SendInput(1, ref input, Marshal.SizeOf(input));
 }