/// <summary> /// Adds single key to the internal collection. Allows to specify scan code and whether it is an extended key. 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. Can be 0.</param> /// <param name="scanCode">Scan code of the physical key. Scan code values are 1-127, but this function allows 1-0xffff. Can be 0.</param> /// <param name="extendedKey">true if the key is an extended key.</param> /// <param name="down">true - key down; false - key up; null (default) - key down-up.</param> /// <exception cref="ArgumentException">Invalid scan code.</exception> public AKeys AddKey(KKey key, int scanCode, bool extendedKey, bool?down = null) { _ThrowIfSending(); if ((uint)scanCode > 0xffff) { throw new ArgumentException("Invalid value.", nameof(scanCode)); } bool isPair; _KFlags f = 0; if (key == 0) { f = _KFlags.Scancode; } else { //don't: if extendedKey false, set true if need. Don't do it because this func is 'raw'. } if (!(isPair = (down == null)) && !down.GetValueOrDefault()) { f |= _KFlags.Up; } if (extendedKey) { f |= _KFlags.Extended; } return(_AddKey(new _KEvent(isPair, key, f, (ushort)scanCode))); }
[FieldOffset(2)] internal ushort ch; //character if IsChar //Event type KeyEvent or KeyPair. internal _KEvent(bool pair, KKey vk, _KFlags siFlags, ushort scan = 0) : this() { this.vk = vk; var f = (byte)siFlags; if (pair) { f |= 16; } _flags = f; this.scan = scan; }
/// <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))); }