namespace WinApiNet.Shell.Console
{
    using System.Runtime.InteropServices;

    /// <summary>
    /// Describes a keyboard input event in a console <see cref="InputRecord"/> structure.
    /// </summary>
    [StructLayout(LayoutKind.Explicit)]
    public struct KeyEventRecord
    {
        /// <summary>
        /// If the key is pressed, this member is <c>true</c>. Otherwise, this member is <c>false</c> (the key is
        /// released).
        /// </summary>
        [FieldOffset(0)]
        [MarshalAs(UnmanagedType.Bool)]
        public bool bKeyDown;

        /// <summary>
        /// The repeat count, which indicates that a key is being held down. For example, when a key is held down, you
        /// might get five events with this member equal to <c>1</c>, one event with this member equal to <c>5</c>, or
        /// multiple events with this member greater than or equal to <c>1</c>.
        /// </summary>
        [FieldOffset(4)]
        public ushort wRepeatCount;

        /// <summary>
        /// A virtual-key code that identifies the given key in a device-independent manner.
        /// </summary>
        [FieldOffset(6)]
        public ushort wVirtualKeyCode;

        /// <summary>
        /// The virtual scan code of the given key that represents the device-dependent value generated by the
        /// keyboard hardware.
        /// </summary>
        [FieldOffset(8)]
        public ushort wVirtualScanCode;

        /// <summary>
        /// Translated Unicode character.
        /// </summary>
        [FieldOffset(10)]
        public char UnicodeChar;

        /// <summary>
        /// The state of the control keys.
        /// </summary>
        [FieldOffset(12)]
        public ControlKeyState dwControlKeyState;
    }
}