[C++] SendInput doesn't work in a game, but AHK's SendInput (from the source code) does

Discuss other programming languages besides AutoHotkey
Sickae
Posts: 4
Joined: 10 Oct 2017, 09:36

[C++] SendInput doesn't work in a game, but AHK's SendInput (from the source code) does

10 Oct 2017, 10:06

So I'm trying to generate a key with the SendInput method in C++. It works very well until it comes to the specific game I want to use it in. It does the job in the game's chat but not in the game itself. I am using AHK for the script I want currently, but I wish to change to a native language to get more control over it. Looked up how AHK does it and apparently it uses the same method as I do, so I'm a bit confused. Why does AHK's method works without any problem and mine doesn't? I have tried many many different methods, but I just can't make it work.
Here's the code:

Code: [Select all] [Expand] [Download] GeSHi © Codebox Plus



And here's my AHK script code that I want to implement in C++ (just a part, no sense copying the whole code):

Code: [Select all] [Download] GeSHi © Codebox Plus

...
while BMActive = 1
{
...
Send yx
...
}
...
Helgef
Posts: 2470
Joined: 17 Jul 2016, 01:02
Contact:

Re: [C++] SendInput doesn't work in a game, but AHK's SendInput (from the source code) does

10 Oct 2017, 13:29

You probably shouldn't use the unicode flag in a game. :beer:
Sickae
Posts: 4
Joined: 10 Oct 2017, 09:36

Re: [C++] SendInput doesn't work in a game, but AHK's SendInput (from the source code) does

10 Oct 2017, 14:12

AHK also uses unicode flag. And trust me, my first try was with scancode, but that doesn't even work in the game's chat. Changed to unicode only after I looked up the AHK source code.
Here it is:

Code: [Select all] [Expand] [Download] GeSHi © Codebox Plus

Helgef
Posts: 2470
Joined: 17 Jul 2016, 01:02
Contact:

Re: [C++] SendInput doesn't work in a game, but AHK's SendInput (from the source code) does

10 Oct 2017, 14:39

Are you certain Send yx end up in that code :angel: . Either verify which part of the source code is relevant for the working ahk script, or look at the msdn documentation for sendinput().
Sickae
Posts: 4
Joined: 10 Oct 2017, 09:36

Re: [C++] SendInput doesn't work in a game, but AHK's SendInput (from the source code) does

10 Oct 2017, 14:53

Yeah, that's my only guess too, that Send doesn't actually use the SendInput method. I'm trying to figure out the source code but couldn't find anything else that generates keys yet. Any help with that would be greatly appreciated. I know the documentation for SendInput and as I said it works everywhere without problems, only in the game I can't get it to work. I know that much that it has something to do with directx's DirectInput but no solution yet.
Helgef
Posts: 2470
Joined: 17 Jul 2016, 01:02
Contact:

Re: [C++] SendInput doesn't work in a game, but AHK's SendInput (from the source code) does

10 Oct 2017, 15:05

Search for SendKeys() (source: Helgef memory :?) in the source code. You need to consider sendmode and possibly you need to understand the concept of sendinput reverting to sendevent.
Sickae
Posts: 4
Joined: 10 Oct 2017, 09:36

Re: [C++] SendInput doesn't work in a game, but AHK's SendInput (from the source code) does

10 Oct 2017, 17:24

I was searching in the source code for hours now and tried a lot more different methods. And finally I made it to work. :) As it turns out the problem was indeed with the flags, I had to set it to 0 and it works like a charm. No idea how to close the thread, so I'll just leave it be. Thank you!

Return to “Other Programming Languages”

Who is online

Users browsing this forum: No registered users and 1 guest