Sentdex / pygta5

Explorations of Using Python to play Grand Theft Auto 5.
MIT License
3.91k stars 823 forks source link

Keys.py/DirectKy.py issue, problem with "SendInput" #118

Closed bhudax closed 5 years ago

bhudax commented 5 years ago

Hi !

I'm experiencing a strange problem occuring in the SendInput function of Key.py. Actually I'vre tryied different codes, and the problem concerns the last part of the function Keys.SendInput()

def SendInput(self, *inputs): nInputs = len(inputs) LPINPUT = INPUT * nInputs pInputs = LPINPUT(*inputs) cbSize = ctypes.c_int(ctypes.sizeof(INPUT)) return ctypes.windll.user32.SendInput(nInputs, pInputs, cbSize)

The following function, sending the keyboard inputs to the drivers, is actually the problematic one.

ctypes.windll.user32.SendInput(nInputs, pInputs, cbSize)

I get this error :
line 468, in SendInput return ctypes.windll.user32.SendInput(nInputs, pInputs, cbSize) ctypes.ArgumentError: argument 2: <class 'TypeError'>: expected LP_INPUT instance instead of INPUT_Array_1

I've tryied using ctypes.pointer to create an LP_Pointer on the inputs, but I get another error saying that the function is waiting for "An instance of LP_Pointer instead of LP_Pointer". Didn't manage to create one though, as LP_Pointer is "not instanciable" ,according to my intepretor.

I have tryied many codes and used google several time before asking, I always fallback on this problem. I think that I might not be the only one concerned by it in the future. Any ideas?

Using python 3.6.4, 32 bits, with windows 10.

Thank's in advance for your attention !

bhudax commented 5 years ago

I found the solution, someone of the community asked about it on stackoverflow afterward and got an answer .

It's a conflict with the pynput module.