lxn / win

A Windows API wrapper package for the Go Programming Language
Other
1.21k stars 315 forks source link

SendInput INPUT struct missing? #7

Closed toqueteos closed 10 years ago

toqueteos commented 10 years ago

Hi there Alexander,

I'm trying to simulate keystrokes but unfortunately win lacks the INPUT struct required. Is there any "easy" way to port it from the C headers to Go?

There's this other package which uses cgo to deal with it but in the project I'm working on I can't use cgo :-1:...

https://github.com/AllenDang/w32/blob/e6b20c288197ddc4eac94ede4f67965a604a7bf4/user32.go#L922

Thanks!

toqueteos commented 10 years ago

Here's what I translated:

// type INPUT struct {
//   DWORD type;
//   _ANONYMOUS_UNION union {
//      MOUSEINPUT mi;
//      KEYBDINPUT ki;
//      HARDWAREINPUT hi;
//   } DUMMYUNIONNAME;
// } INPUT,*PINPUT,*LPINPUT;

type INPUT struct {
    Type      uint32
    AnonUnion interface{}
}

// typedef struct tagMOUSEINPUT {
//   LONG      dx;
//   LONG      dy;
//   DWORD     mouseData;
//   DWORD     dwFlags;
//   DWORD     time;
//   ULONG_PTR dwExtraInfo;
// } MOUSEINPUT, *PMOUSEINPUT;

type MOUSEINPUT struct {
    Dx          int32
    Dy          int32
    MouseData   uint32
    DwFlags     uint32
    Time        uint32
    DwExtraInfo uintptr // int?
}

// typedef struct tagKEYBDINPUT {
//   WORD      wVk;
//   WORD      wScan;
//   DWORD     dwFlags;
//   DWORD     time;
//   ULONG_PTR dwExtraInfo;
// } KEYBDINPUT, *PKEYBDINPUT;

type KEYBDINPUT struct {
    WVk         int16
    WScan       int16
    DwFlags     uint32
    Time        uint32
    DwExtraInfo uintptr // int?
}

// typedef struct tagHARDWAREINPUT {
//   DWORD uMsg;
//   WORD  wParamL;
//   WORD  wParamH;
// } HARDWAREINPUT, *PHARDWAREINPUT;

type HARDWAREINPUT struct {
    UMsg    uint32
    WParamL int16
    WParamH int16
}
lxn commented 10 years ago

It's already there: https://github.com/lxn/win/blob/master/user32.go#L1376

toqueteos commented 10 years ago

Oh god, I searched but GitHub said 0 results :-1:

Thanks Alex!

lxn commented 10 years ago

No problemo :-)