Solved How to Send Keystrokes to an Inactive Window

Hexui Undetected CSGO Cheats Sinkicheat PUBG Cheat

iKasu

Newbie
Full Member
Jan 5, 2013
22
212
0
Good Morning/evening GDH :3

I currently work on a Bot for the Online MMORPG "Fiesta Online" and i found a little problem for me x.x
I can't send any Keys to this Game while it's not active / in focus.

I tryed to do it via SendMessage / PostMessage but it doesn't work so i used Spy++ to locate a SubClass maybe this should help but it didn't.

Here's a little sample written without copying it from my Source:
C++:
void test(){
HWND hWindow = FindWindow("Gamebryo Application","FiestaOnline");
if(!hWindow) return 0;
HWND hWindow2 = FindWindowEx(hWindow, NULL, "Gamebryo Application", NULL);
if(!hWindow2) return 0;
SendMaMessage(hWindow2, "abcdefg");
}

void SendMaMessage(HWND hwnd, char String[]) {
    for (int x = 0; String[x] != 0; x++) { SendMaKey(hwnd, String[x]); }
}

void SendMaKey(HWND hwnd, BYTE vk)  {

     SendMessage(hwnd, vk, WM_KEYDOWN, 0);
     PostMessage(hwnd, WM_CHAR, vk, 0);
         SendMessage(hwnd, vk, WM_KEYUP, 0);
}
I also know there must be a walk function because you can press on the floor and he will walk to this point where you pressed but
i can't find it via ollydbg x.x

so my question is How to send keystrokes to an inactive Window?

Any Help is welcome and i hope you guys can help me.

LG
 
Last edited by a moderator:

Chuck E

Coder
Dank Tier Donator
Nobleman
Jan 2, 2013
122
588
1
Apparently X-Tap anti cheat is used by Fiesta Online
That is why it does not register the PostMessages :(

" You'll see in this list of supported games from the Wiki that Dragona is listed as not compatible due to X-Trap. I realize you don't play Dragona, but the reason Fiesta Online isn't compatible is because of X-Trap and there's nothing that can be done about that. "

Further reading, and it looks like X-Trap has stopped PostMessage from working, by creating a reference to that function, and that reference involves the function doing nothing.
Therefore the only way round this, it seems, is to reverse engineer it and alter/remove that reference, if possible.
See example here:

I believe in order to remove the listener you have to have a reference to the same function so like this:
C++:
var f = function(e){
console.log('hi');
window.removeEventListener("message", f, false);
}
window.addEventListener("message", f);
So the reason your's doesn't work is because it doesn't have a reference to that function as a listener.

This is what is called an eduguess on my part (educated guess) :D It could be total <expletive here> ;)
 
Last edited by a moderator:

c5

Kim Kong Trasher
Dank Tier VIP
Dank Tier Donator
Jul 19, 2012
1,187
12,638
76
Haven't tried before but maybe you can directly call the callback of the window. Could be the game just doesn't handle input when not in focus.

Try adding a sleep between sending keydown and keyup.

What about SendInput?
 
Last edited:

Szaka

Coder
Full Member
Nobleman
Mar 14, 2013
161
718
3
PostMessage with keyup and keydown

To find the walk function reverse from "send" api
 

iKasu

Newbie
Full Member
Jan 5, 2013
22
212
0
PostMessage with keyup and keydown

To find the walk function reverse from "send" api
How u mean this? I tryed to look for something like walk, run, click but whenever i do a breakpoint the game doesn't care x.x

Haven't tried before but maybe you can directly call the callback of the window.

How u mean this?

Well i checked with Spy++ that there is another Class "Gamebryo Application" and there i found the messages but
whenever i enter something "abcbaasdhjasdgaisdhi" it always shows me WM_COMMAND instead of WM_KEYDOWN or whatever x.x

LG

Edit: Added some Screens:

Here is what i get when i set the Focus to the Game and Send a "a" Key to it:
4k1Zk.jpg


This is the Handle i get (the 2nd one) - The first one doesn't show's me anything if i enter something
So it's the 2nd one:
View attachment 2014
 
Last edited:

Szaka

Coder
Full Member
Nobleman
Mar 14, 2013
161
718
3
First make sure you got valid HWND by testing it with some API which has visible results and then try
PostMessage(MyHwnd, WM_KEYDOWN, Virtual key code for exampel VK_F1, NULL);

Aha,and run it as administrator
 

iKasu

Newbie
Full Member
Jan 5, 2013
22
212
0
Okay after few more trys and fails i got the right handle, the right wparam and lparam - but.... it still doesn't work >.<

4kkRI.png

Thats my Function:
C++:
void SendMyKeyPls(int key, LPCSTR ClassName, LPCSTR WindowName){

HWND hWnd = FindWindowA(ClassName, WindowName);
    if(hWnd){
		LPARAM LPARAMDOWN = 0x00000001; 
		LPARAM LPARAMUP = 0xC0000001; 
                LPARAM SendKey = (MapVirtualKey(Key, 0) << 0x10);
		PostMessage(hWnd, WM_KEYDOWN, VK_I, (LPARAM)( LPARAMDOWN | SendKey  ));
                Sleep(100);
		PostMessage(hWnd, WM_KEYDOWN, VK_I, (LPARAM)( LPARAMDOWN | SendKey  ));
}

SendMyKeyPls(VK_I /* 0x49 */, "Gamebryo Application", "FiestaOnline");
 
Last edited:

Chuck E

Coder
Dank Tier Donator
Nobleman
Jan 2, 2013
122
588
1
This is how I did it in a simple program (C#) with 2 buttons, that sends the W key to WoW game client
Open Game button
Send W button



// GLOBAL VARIABLE TO HOLD THE GAME'S PROCESS
private Process gameProcess;

// THIS IS ATTACHED TO A BUTTON - btnOpenGame
// open the game client
gameProcess = new Process();
gameProcess.StartInfo.FileName = @"C:\World of Warcraft - Vanilla - Ballistix\WoW.exe";
gameProcess.Start();



// THIS IS ATTACHED TO A BUTTON - btnSendW
PostMessage(gameProcess.MainWindowHandle, WM_KEYDOWN, VK_W, 0);


EDIT: Just in case you are going to try this in C#, you need to add:
// add this directive
using System.Runtime.InteropServices; // used for win32 API - mouse/keyboard detection
// add this to your variable declaration area
[DllImport("user32.dll")]
static extern bool PostMessage(IntPtr hWnd, uint Msg, int wParam, int lParam);
 
Last edited:

iKasu

Newbie
Full Member
Jan 5, 2013
22
212
0
This is how I did it in a simple program (C#) with 2 buttons that sends the key W to WoW game client
Open Game button
Send W button



// GLOBAL VARIABLE TO HOLD THE GAME'S PROCESSprivate Process gameProcess;

// THIS IS ATTACHED TO A BUTTON - btnOpenGame
// open the game client
gameProcess = new Process();
gameProcess.StartInfo.FileName = @"C:\World of Warcraft - Vanilla - Ballistix\WoW.exe";
gameProcess.Start();



// THIS IS ATTACHED TO A BUTTON - btnSendW
PostMessage(gameProcess.MainWindowHandle, WM_KEYDOWN, VK_W, 0);


EDIT: Just in case you are going to try this in C#, you need to add:
// add this directive
using System.Runtime.InteropServices; // used for win32 API - mouse/keyboard detection
// add this to your variable declaration are
[DllImport("user32.dll")]
static extern bool PostMessage(IntPtr hWnd, uint Msg, int wParam, int lParam);

Not working And Chuck E havn't got it to work too x.x
How the fuck do we get this to work >.<
 

bzh

Newbie
Full Member
Oct 3, 2012
28
292
1
Here's my function that I use for my bot, feel free to use it to send keystrokes or modify it. I'm able to hide my game window and it runs just fine.

C++:
void SendKeyInput(HWND &wHANDLE, WPARAM key)
{
	PostMessage(wHANDLE, WM_KEYDOWN, key, 0);
	Sleep(50);
	PostMessage(wHANDLE, WM_KEYUP, key, 0);
}
Usage
C++:
SendKeyInput(wHANDLE, VK_SPACE);
 

iKasu

Newbie
Full Member
Jan 5, 2013
22
212
0
Here's my function that I use for my bot, feel free to use it to send keystrokes or modify it. I'm able to hide my game window and it runs just fine.

C++:
void SendKeyInput(HWND &wHANDLE, WPARAM key)
{
	PostMessage(wHANDLE, WM_KEYDOWN, key, 0);
	Sleep(50);
	PostMessage(wHANDLE, WM_KEYUP, key, 0);
}
Usage
C++:
SendKeyInput(wHANDLE, VK_SPACE);
It does not work for this game. I didn't found another way and it drives me crazy x.x

maybe a Proper programmer is able to get this shit to work x.x

LG
 

NoTeefy

Newbie
Full Member
Mar 30, 2016
7
72
0
I'm sorry for bumping such an old thread but I tried it in the same year as iKasu and never finished it because I got stuck on that problem too.
Does a new workaround on that specific problem exist?
What did he mean with "syscall"?


Best regards
 

NoTeefy

Newbie
Full Member
Mar 30, 2016
7
72
0
So I could try to send the commands over system calls, right? What do I need for that? Do you have some documents to get me into it?
That would be very friendly :)

Best regards
 

NoTeefy

Newbie
Full Member
Mar 30, 2016
7
72
0
It's me again. I tested some different approaches and got it to work. It's smooth as fuck and can't be detected by any vac.
I still don't know why Kazu didn't found it by himself, it's pretty easy :)
And btw: Thanks for the tip with sys call, that really helped me!

Best regards
 

Rake

Cesspool Admin
Administrator
Jan 21, 2014
12,140
78,998
2,394
It's me again. I tested some different approaches and got it to work. It's smooth as fuck and can't be detected by any vac.
I still don't know why Kazu didn't found it by himself, it's pretty easy :)
And btw: Thanks for the tip with sys call, that really helped me!

Best regards
source code or it never happened
 

mambda

headass
Escobar Tier VIP
Trump Tier Donator
Jun 25, 2014
2,298
37,938
269
Yep, manual syscalls are pretty much undetectable for a usermode anticheat ( only exception being if they hook you for some unknown reason :p ), not as effective against a r0 anticheat, depending on your OS architecture / what you're trying to call.
 

NoTeefy

Newbie
Full Member
Mar 30, 2016
7
72
0
I'm gonna post my code here when I've finished and cleaned it :)
Now I've got to another problem: My calls work and I'm able to send Text etc to the Game Window. But one little thing still doesn't work: If I'm trying to send a message to the chat, I need to open the chatbar.
This strangely works only if I manually press the keys even tho they seem to be exact the same as my programmed ones (seen in Spy++).
I've read something about trampolines. Is that the right approach?
Do you have something documented which uses a trampoline?

Best regards
 

mambda

headass
Escobar Tier VIP
Trump Tier Donator
Jun 25, 2014
2,298
37,938
269
I dont believe hooking is what you need here.

try PostMessage/SendMessage or whatever theyre called
keybd_event, shit like that
 
Attention! Before you post:

Read the How to Ask Questions Guide
99% of questions are answered in the Beginner's Guide, do it before asking a question.

No Hack Requests. Post in the correct section.  Search the forum first. Read the rules.

How to make a good post:

  • Fill out the form correctly
  • Tell us the game name & coding language
  • Post everything we need to know to help you
  • Ask specific questions, be descriptive
  • Post errors, line numbers & screenshots
  • Post code snippets using code tags
  • If it's a large project, zip it up and attach it

If you do not comply, your post may be deleted.  We want to help, please make a good post and we will do our best to help you.

Community Mods