Because unions break type safety, the only way to access them in Go is with the unsafe package. I think you could do it something like this:
*(*C.KEYBDINPUT)(unsafe.Pointer(uintptr(unsafe.Pointer(&input)) + unsafe.Sizeof(C.DWORD))) = keybdinput
If I needed to deal with these types much, I would declare wrapper types to make it easier:
type tagKbdInput struct {
typ uint32
ki C.KEYBDINPUT
}
type tagMouseInput struct {
typ uint32
mi C.MOUSEINPUT
}
type tagHardwareInput struct {
typ uint32
hi C.HARDWAREINPUT
}
Then I could use a simpler conversion through unsafe.Pointer (without pointer arithmetic) to access them:
(*tagKbdInput)(unsafe.Pointer(&input)).ki = keybdinput