aIW|SendCommand from external app

Posts 1–15 of 21 · Page 1 of 2
aIW|SendCommand from external app
Code:
void WriteCommandToConsole(string Command)
{
    HWND hwnd = FindWindow(NULL,L"aIW Console");
    HWND childHwnd = FindWindowEx(hwnd,NULL,L"Edit",NULL);
    const int Lenght = Command.length();

    char cCommand[Lenght];

    for(int i = 0; i < Command.size();i++)
    {
        cCommand[i] = Command.at(i);
    }

    for(int i = 0,inInt; i < Command.size(); i++)
    {
        inInt = cCommand[i];
        SendMessage(childHwnd,WM_CHAR,inInt,true); 
    }
    SendMessage(childHwnd,WM_CHAR,VK_RETURN,true);

}

Usage:

Code:
WriteCommandToConsole("cg_drawFps 1");
Creditz: me

Enjoy

I found out a good type cast so here is a improved version:

Code:
void SendCommand(LPCTSTR Command)
{
    static HWND editBox = FindWindowEx(FindWindow(NULL, L"aIW Console"),0,L"Edit",0);
    if(editBox == NULL)
        return;
    else
    {
        SendMessage(editBox,WM_SETTEXT,0,(LPARAM)((LPCTSTR)Command));
        SendMessage(editBox,WM_CHAR,VK_RETURN,0);
    }
}
amazing, and no need for offsets. +1
Quote Originally Posted by user590177 View Post
amazing, and no need for offsets. +1
Thank you, i am back now
Wow, nice one, definitely some rep + for this.

Question though, why the double for loops? Doesn't this work?
Code:
void WriteCommandToConsole(string Command)
{
    static HWND childHwnd = FindWindowEx(FindWindow(NULL,L"aIW Console"),NULL,L"Edit",NULL);
    short length = Command.length();

    for(short i = 0; i < length; ++i)
    {
        SendMessage(childHwnd,WM_CHAR,(int)Command.at(i),true); 
    }
    SendMessage(childHwnd,WM_CHAR,VK_RETURN,true);

}
Optimizations: Shorts instead of ints as messages are never 2.1 billion in length, changed i++ to ++i to make use of the INC instruction instead of the ADD instruction in assembly, instead of calling command.length() every loop (I learned that it actually checks the length every single loop and ends up slowing down the loops when I was learning PHP), and straight casting into int instead of using a temporary int holder. The handle to Edit is only initialized once as it's static, since the window handle shouldn't change between writes.
@shadowx360 You can use an unsigned short because i is never negative. You should also beware that if you call this function before the console is open, it will not work.
Quote Originally Posted by alteriw-norecoil View Post
@shadowx360 You can use an unsigned short because i is never negative. You should also beware that if you call this function before the console is open, it will not work.
If you want to follow the syntax rules you should use a LPARAM(long)
Code:
void WriteCommandToConsole(string Command)
{
    static HWND childHwnd = FindWindowEx(FindWindow(NULL,L"aIW Console"),NULL,L"Edit",NULL);
    if(childHwnd == NULL)
    {
          childHwnd = FindWindowEx(FindWindow(NULL,L"aIW Console"),NULL,L"Edit",NULL);
          if(childHwnd == NULL)
                 return;
    }
    short length = Command.length();

    for(short i = 0; i < length; ++i)
    {
        SendMessage(childHwnd,WM_CHAR,(int)Command.at(i),true); 
    }
    SendMessage(childHwnd,WM_CHAR,VK_RETURN,true);

}
Fixed issue in case the hwnd is null.
I found out a good type cast so here is a improved version:

Code:
void SendCommand(LPCTSTR Command)
{
    static HWND editBox = FindWindowEx(FindWindow(NULL, L"aIW Console"),0,L"Edit",0);
    if(editBox == NULL)
        return;
    else
    {
        SendMessage(editBox,WM_SETTEXT,0,(LPARAM)((LPCTSTR)Command));
        SendMessage(editBox,WM_CHAR,VK_RETURN,0);
    }
}
And if you're not compiling in Unicode you can just directly cast from char* to LPARAM
winberg I think you should put that into the main post. But do not delete the old code, who knows?
I make a .dll file with first codes and join a server inject the .dll file and write second command... Right?
Quote Originally Posted by DahInternetz View Post
I make a .dll file with first codes and join a server inject the .dll file and write second command... Right?
You don't even need to inject a DLL to use this code.

Also, the syntax into your signature is wrong.
Quote Originally Posted by user590177 View Post
winberg I think you should put that into the main post. But do not delete the old code, who knows?
I doesn't seem to be able to edit it should i create a new thread?

Quote Originally Posted by greg123 View Post
how use this code
Do you know any programming language?
Quote Originally Posted by winberg View Post
I doesn't seem to be able to edit it should i create a new thread?



Do you know any programming language?
ask @master131 or @Heartview to fix dat.
Posts 1–15 of 21 · Page 1 of 2
This thread is closed for replies.

Similar Threads

Tags for this Thread

None

Talk with us