I looked up on MSDN before and there was no two versions of it thats why i ran it just as SendInput.

But even if i run it as SendInputA or SendInputW it doesnt make a difference, it wont break.

By the way i compiled the .exe with the -Zi switch.

I dont know if that counts.

07-23-2011

adeyblue

Quote:

Originally Posted by Salem

Perhaps set a breakpoint on SendInputW, if you compiled for UNICODE.

There is no SendInputW since the function doesn't have a c-string parameter

OP: the first number to SendInput is the number of inputs. Setting it to 4 for anything except the first call access memory that contains who knows what, it also means that it tries to send all four inputs when you should be only sending the first two. Using it twice in first loop means it tries to send 8 inputs per character. Look at the code you copied from, it sends a both a down and a up keystroke but only uses SendInput once.

No offence but regardless of how many hours a day/week you devote to programming, after three and a half years, magic numbers, guessing and not reading the documentation should be mistakes that are far behind you.

07-23-2011

Ducky

Thank you Adeyblue for taking the time and helping me.

No offence taken, i know im not the brightest crayon in the box. :)

Still, having said that, i was aware that the first arg is the number of structures but in the second arg i only call 1,2 and 3,4 respectively.

So see i thought it was possible to do it that way.

Fortunately you tell me its not so ill be able to fix this code.

By the way neither Salem nor Novocain caught on it but maybe they werent looking at it too hard.

Also note that in order to manipulate shift, alt or ctrl keys along with the sent character you may need to send more than 2 inp structs... for example to send a capital a you will need to first do shift key down, then a key down, a key up and finally shift key up... a total of 4 structs. For multikey combinations you may have to send as many as 8.

Since this will only send to the focused window or control, a far more reliable method --provided you know the window or thread handle-- is to use either PostMessage() or PostThreadMessage() directly to the desired program sending WM_KEYDOWN and WM_KEYUP messages.

07-23-2011

Ducky

Thanks CommonTater for your effort but look again at the function i posted.

It can send perfectly well even a string.

What i was trying to add to this function is the possibility to press a button after a sending a string.

I tried to follow Adeyblue advice and reduced the input structure size to two but the issue stays the same (the key stays down).

I think the problem is the use of KEYEVENTF_UNICODE and KEYEVENTF_SCANCODE together, even if it gets overwritten.

07-23-2011

CommonTater

Quote:

Originally Posted by Ducky

Thanks CommonTater for your effort but look again at the function i posted.

It can send perfectly well even a string.

What i was trying to add to this function is the possibility to press a button after a sending a string.

I tried to follow Adeyblue advice and reduced the input structure size to two but the issue stays the same (the key stays down).

I think the problem is the use of KEYEVENTF_UNICODE and KEYEVENTF_SCANCODE, even if it gets overwritten.

More likely the problem is that you are sending everything twice...
The second time starts at inp[1] and is sending 4 packets which means you are sending garbage beyond the end of your array.
Send it once... and only once starting at inp[0].

Also take a look at the API description of the function, you probably don't want to use either unicode or scancode flags in there, since you are sending a string you want to send virtual keys along with shift keys for capital letters....