sending key to inactive window

07/18/2012 13:01 fear-x#1
im a newbie with c++ today and im trying to make a dll to send key to inactive window but i tryed calling it and nothing gets sent dont know if i call it right or not .

DLL:
Code:
#include "main.h"
#include <windows.h>

// a sample exported function
int DLL_EXPORT SendMessage(int x = 0){
    //HWND Client = FindWindow(0, "D3D Window");
    HWND hwnd = FindWindow("D3D Window", NULL);


  //  SendInput(hwnd, '2');
    SendMessage(hwnd, WM_KEYDOWN, VK_F4, 0);
    Sleep(300);
    SendMessage(hwnd, WM_KEYUP, VK_F4, 0);
    return x;

  //  PostMessage(hwnd, WM_KEYDOWN, 0x43, 0);
 //     PostMessage(hwnd, WM_CHAR, (WPARAM)'C', 0);
 //     PostMessage(hwnd, WM_KEYUP, 0x43, 0);

//      cout << "pressed" << endl;
	MessageBox(0, "Join us at Inferno Dev!", "DLL Message", MB_OK | MB_ICONINFORMATION);
    return x;
}

BOOL WINAPI DllMain(HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpvReserved)
{
    switch (fdwReason)
    {
        case DLL_PROCESS_ATTACH:
            // attach to process
            // return FALSE to fail DLL load
            break;

        case DLL_PROCESS_DETACH:
            // detach from process
            break;

        case DLL_THREAD_ATTACH:
            // attach to thread
            break;

        case DLL_THREAD_DETACH:
            // detach from thread
            break;
    }
    return TRUE; // successful
}

AutoIt DLL CALL:
Code:
DllCall("test.dll", "none", 'SendMessage')

please help me how can i make the dll send a key to inactive window :)
tryed googling tutorials of c++ but nothing at all o.o
07/19/2012 12:57 XxharCs#2
when u make a dll then u dont need the FindWindow function because, when you inject ur dll then dll "is" in the process..

Quote:
Code:
switch (fdwReason)
    {
        case DLL_PROCESS_ATTACH:
            // attach to process
            // return FALSE to fail DLL load
            break;
are u creating the thread, if i may ask ??

doing something like this in the DLL_PROCESS_ATTACH:
Code:
CreateThread(0, 0, &BotThread , 0, 0, 0);

are u injecting the dll at all or what ?
Quote:
AutoIt DLL CALL:
Code:
Code:
DllCall("test.dll", "none", 'SendMessage')
i mean yeah, you call the dll, but do you inject it ?

and try the SendInput function

if i missunderstood something, then correct me..
07/19/2012 13:04 fear-x#3
ow i didnt know i must inject it :D

well how do i attach it to another process? :) so it would send keys to the game whilst inactive.

and apreciate your help.
07/19/2012 13:05 Dr. Coxxy#4
you misunderstood everything.
he compiled it as dll and loaded it into his autoit project to use the exported function.

you dont need to inject it.
07/19/2012 13:06 XxharCs#5
make an injector^^
or use some injectors that already exists, for example WinInject :)

Edit: Yeah Coxxy but he still need to load it from there in the process he want to or ?..
07/19/2012 13:11 fear-x#6
i just want the dll to send specific key in each function in that dll :P posible?
07/19/2012 13:44 Dr. Coxxy#7
he doesnt want to inject anything he just makes a library and exports the sendmessage function to use it in his autoit3 project.

@fear-x google, i have no clue about autoit, but afaik you can call the winapi directly.
so you won't need the dll.
07/19/2012 14:27 fear-x#8
well with autoit it wont work thats the thing :) xtrap is blocking it :)

so i thought dll would do the trick...
07/19/2012 14:50 Dr. Coxxy#9
very unlikely to work.
07/19/2012 15:04 fear-x#10
anyway to make it work? even without dll ? :s i can make simple send to work or in c++ its keybd_event() but not to inactive window :/
07/19/2012 16:00 tnd0#11
Sendkey (=SendMessage) doesnt work. A window has a message queue in which it peeks for messages, but it does not receive messages while inactive, to save CPU time. Plus, if your window is a game, it probably uses directinput which doesnt check the message queue anyway.

On a side-note; your signature is telling everyone that you have no idea of computer science.
07/19/2012 16:40 fear-x#12
lol? my sig tells u wat? ;d
07/19/2012 17:35 Dr. Coxxy#13
autoit is the death keyword for coding ;)

EDIT:

Quote:
Originally Posted by tnd0 View Post
Sendkey (=SendMessage) doesnt work. A window has a message queue in which it peeks for messages, but it does not receive messages while inactive, to save CPU time.
this is just wrong.
windows wont send normal windows messages anymore, but the messagepump is still active even if the window has not the focus.
if you place a message in the messagequeue via send/postmessage windows will reactivate the messagepump and the window will proceed the message.
but most likely the game/the anticheat has a check wether the window is ontop / the input is emulated.
or the game simply uses directinput.
07/19/2012 18:33 fear-x#14
well the game has D3D Window and i know that D3D Windows are pain in the ass to work with
07/19/2012 22:56 tnd0#15
Quote:
if you place a message in the messagequeue via send/postmessage windows will reactivate the messagepump and the window will proceed the message.
yes, windows will do that. however, on a custom message loop you dont necessarily check any messages (if you suspend your window thread or check in a peekmessage loop for example).