static public void PressKeyVK(ScottsUtils.WinAPI.KeyCode key, bool press, bool release, bool compatible) { uint scanCode = ScottsUtils.WinAPI.MapVirtualKey((uint)key, 0); uint extended = IsExtendedKey(key) ? (uint)ScottsUtils.WinAPI.KeybdEventFlag.ExtendedKey : 0; if (compatible) { extended = 0; } if (press) { ScottsUtils.WinAPI.keybd_event((byte)key, (byte)scanCode, (ScottsUtils.WinAPI.KeybdEventFlag)extended, 0); } if (release) { ScottsUtils.WinAPI.keybd_event((byte)key, (byte)scanCode, (ScottsUtils.WinAPI.KeybdEventFlag)(extended | (uint)ScottsUtils.WinAPI.KeybdEventFlag.KeyUp), 0); } }
static public bool IsExtendedKey(ScottsUtils.WinAPI.KeyCode key) { switch (key) { case ScottsUtils.WinAPI.KeyCode.Left: case ScottsUtils.WinAPI.KeyCode.Up: case ScottsUtils.WinAPI.KeyCode.Right: case ScottsUtils.WinAPI.KeyCode.Down: case ScottsUtils.WinAPI.KeyCode.Prior: case ScottsUtils.WinAPI.KeyCode.Next: case ScottsUtils.WinAPI.KeyCode.End: case ScottsUtils.WinAPI.KeyCode.Home: case ScottsUtils.WinAPI.KeyCode.Insert: case ScottsUtils.WinAPI.KeyCode.Delete: case ScottsUtils.WinAPI.KeyCode.Divide: case ScottsUtils.WinAPI.KeyCode.NumLock: return(true); default: return(false); } }
static public void PressKeyVK(ScottsUtils.WinAPI.KeyCode key) { PressKeyVK(key, true, true, false); }