[StructLayout(LayoutKind.Explicit)]struct INPUT {
[FieldOffset(0)] int type;
[FieldOffset(4)] MOUSEINPUT mi;
[FieldOffset(4)] KEYBDINPUT ki;
[FieldOffset(4)] HARDWAREINPUT hi;
}
Structure INPUT_TYPE
<FieldOffset(0)> Dim dwType As Integer
<FieldOffset(4)> Dim mi As MOUSEINPUT
<FieldOffset(4)> Dim ki As KEYBDINPUT
<FieldOffset(4)> Dim hi As HARDWAREINPUT
End Structure
MOUSEINPUT, KEYBDINPUT, HARDWAREINPUT
The last 3 fields are a union, which is why they are all at the same memory offset.
On 64-Bit systems, the offset of the mi, ki and hi fields is 8, because the nested struct uses the alignment of its biggest member, which is 8 (due to the 64-bit pointer in dwExtraInfo). It might therefore be more reasonable, to use three structs instead of a hard-coded layout.