SendInput() without focusing

Need Help With an Existing Feature in Memory Hacking Software? Ask Here

Moderators: g3nuin3, SpeedWing, WhiteHat, mezzo

SendInput() without focusing

Postby trialusert » Sun Nov 01, 2009 7:48 am

Is there any way to send input to a window without using SetForegroundWindow() or Focus()?
I'm trying to send text to a game console. What I'm doing now is finding the console window, focusing it and sending the input; problem is that it stops the player from moving (because the console gets focused). So I'm searching for a way to send inputs to windows without focusing them. Is it possible?
User avatar
trialusert
NULL
 
Posts: 155
Joined: Tue May 20, 2008 6:19 pm

Postby L. Spiro » Sun Nov 01, 2009 3:45 pm

If sending WM_INPUT, WM_KEYDOWN, and WM_KEYUP directly to the window does not work then it is impossible.


L. Spiro
Our songs remind you of songs you’ve never heard.
User avatar
L. Spiro
L. Spiro
 
Posts: 3129
Joined: Mon Jul 17, 2006 10:14 pm
Location: Tokyo, Japan

Postby trialusert » Sun Nov 01, 2009 7:29 pm

SendMessage() solved my problem.
User avatar
trialusert
NULL
 
Posts: 155
Joined: Tue May 20, 2008 6:19 pm

Postby trialusert » Sun Nov 01, 2009 8:24 pm

I noticed that SendMessage() changes the console window name, and not the console text. This is the code I'm using to find the console window and send text to it:

Code: Select all
[DllImport("user32.dll")]
        public static extern IntPtr FindWindow(string lpClassName, string lpWindowName);

IntPtr hWnd_Console = FindWindow(null, "ConsoleName");


Code: Select all
[DllImport("user32.dll")]
        public static extern int SendMessage(IntPtr hWnd, int uMsg, int wParam, string lParam);

SendMessage(hWnd_Console, WM_SETTEXT, 0, txt);


I figured I need to send the message to the right window class, but I don't know the class name. In Windows Notepad I found it using FindWindowEx() and setting "Edit" as the class name:

Code: Select all
[DllImport("user32.dll")]
        public static extern IntPtr FindWindowEx(IntPtr hwndParent, IntPtr hwndChildAfter, int lpszClass, string lpszWindow);

IntPtr child = FindWindowEx(consoleHandle, new IntPtr(0), "Edit", null);


How can I find the class name for my console "edit box" ?
User avatar
trialusert
NULL
 
Posts: 155
Joined: Tue May 20, 2008 6:19 pm

Postby troublesh00ter » Mon Nov 02, 2009 12:21 am

I did the same thing a while ago, but can't find the code right now. I will search more thoroughly tomorrow.

From what I can remember:
FindWindow will find the application's parent window.
This parent window has several child handles, one of them being the editbox.

So from the parent window you'd enumerate the child windows until you hit the edit box.

If that doesn't make sense to you then I will try to find the code tomorrow, although it is C++.
troublesh00ter
Sir Hacks-A-Lot
 
Posts: 30
Joined: Mon Jun 01, 2009 2:54 pm
Location: The Netherlands

Postby trialusert » Mon Nov 02, 2009 12:45 am

It makes sense, but I don't know how to do this. I would be grateful if you could share the code with me. Thank you!
User avatar
trialusert
NULL
 
Posts: 155
Joined: Tue May 20, 2008 6:19 pm

Postby trialusert » Tue Nov 03, 2009 1:02 am

I managed to find all child windows, but none of them seemed to be the editbox. I sent text (using WM_SETTEX) to each of the console child windows, but nothing appeared in the game.
L.Spiro, can you explain to me why it might be impossible? This game has no anti-hack...
User avatar
trialusert
NULL
 
Posts: 155
Joined: Tue May 20, 2008 6:19 pm

Postby L. Spiro » Tue Nov 03, 2009 6:51 am

If the game uses DirectX you need to send the input to the hidden window.

Otherwise the game may be polling keystates via GetKeyStateAsync(), which you would need to hook to trick.


L. Spiro
Our songs remind you of songs you’ve never heard.
User avatar
L. Spiro
L. Spiro
 
Posts: 3129
Joined: Mon Jul 17, 2006 10:14 pm
Location: Tokyo, Japan

Postby trialusert » Tue Nov 03, 2009 7:42 am

It is an OpenGL game, does it work the same?
User avatar
trialusert
NULL
 
Posts: 155
Joined: Tue May 20, 2008 6:19 pm

Postby L. Spiro » Tue Nov 03, 2009 9:28 am

It can work in many ways.
Hook GetKeyStateAsync().
Send WM_INPUT, WM_KEYDOWN, and WM_KEYUP instead of setting the text.


L. Spiro
Our songs remind you of songs you’ve never heard.
User avatar
L. Spiro
L. Spiro
 
Posts: 3129
Joined: Mon Jul 17, 2006 10:14 pm
Location: Tokyo, Japan

Postby troublesh00ter » Thu Nov 05, 2009 2:42 am

I'm terribly sorry but I forgot about this thread. And also I haven't gotten around yet to find the source for you. I'm in the middle of a few tough weeks at uni and preparing for a trip abroad, for work.

I will see if I can find time tomorrow to look up the source, but following L. Spiro's suggestion to hook GetKeyStateAsync() is probably a more solid solution.
troublesh00ter
Sir Hacks-A-Lot
 
Posts: 30
Joined: Mon Jun 01, 2009 2:54 pm
Location: The Netherlands


Return to Help

Who is online

Users browsing this forum: No registered users and 0 guests

cron