/// <summary> /// Sends key. /// Not used for keys whose scancode can depend on keyboard layout. To get scancode, uses keyboard layout of current thread. /// </summary> /// <param name="k"></param> /// <param name="downUp">1 down, 2 up, 0 down-up.</param> internal static void SendKey(KKey k, int downUp = 0) { uint f = 0; if (KeyTypes_.IsExtended(k)) { f |= Api.KEYEVENTF_EXTENDEDKEY; } ushort scan = VkToSc(k); if (0 == (downUp & 2)) { SendKeyEventRaw(k, scan, f); } if (0 == (downUp & 1)) { SendKeyEventRaw(k, scan, f | Api.KEYEVENTF_KEYUP); } }
/// <summary> /// Adds single key, specified as <see cref="KKey"/>, to the internal collection. It will be sent by <see cref="Send"/>. /// Returns self. /// </summary> /// <param name="key">Virtual-key code, as <see cref="KKey"/> or int like <c>(KKey)200</c>. Valid values are 1-255.</param> /// <param name="down">true - key down; false - key up; null (default) - key down-up.</param> /// <exception cref="ArgumentException">Invalid <i>key</i> (0).</exception> public AKeys AddKey(KKey key, bool?down = null) { _ThrowIfSending(); if (key == 0) { throw new ArgumentException("Invalid value.", nameof(key)); } bool isPair; _KFlags f = 0; if (!(isPair = (down == null)) && !down.GetValueOrDefault()) { f |= _KFlags.Up; } if (KeyTypes_.IsExtended(key)) { f |= _KFlags.Extended; } return(_AddKey(new _KEvent(isPair, key, f))); }