public static void Send(int VKey, KeyboardEvent e = KeyboardEvent.Both) { uint extended_flag = (VKey >= 16 && VKey <= 18) || (VKey >= 160 && VKey <= 165) ? 0 : KEYEVENTF_EXTENDEDKEY; Key key = (Key)System.Windows.Input.KeyInterop.KeyFromVirtualKey(VKey); if (e.HasFlag(KeyboardEvent.Down)) { keybd_event((byte)VKey, 0, extended_flag, 0); KeyboardFilter.Expect(key, true); } if (e.HasFlag(KeyboardEvent.Up)) { keybd_event((byte)VKey, 0, extended_flag | KEYEVENTF_KEYUP, 0); KeyboardFilter.Expect(key, false); } }
public static void Send(int vKey, KeyboardEvent e = KeyboardEvent.Both) { var extendedFlag = (vKey >= 16 && vKey <= 18) || (vKey >= 160 && vKey <= 165) ? 0 : KEYEVENTF_EXTENDEDKEY; var key = KeyInterop.KeyFromVirtualKey(vKey); if (e.HasFlag(KeyboardEvent.Down)) { keybd_event((byte)vKey, 0, extendedFlag, 0); KeyboardFilter.Expect(key, true); } if (e.HasFlag(KeyboardEvent.Up)) { keybd_event((byte)vKey, 0, extendedFlag | KEYEVENTF_KEYUP, 0); KeyboardFilter.Expect(key, false); } }