I have a 3rd party program which contains a chat area. I am trying to create a function which sends a message to that chat. I have the handle to the parent window and the handle to the Edit window where you type. I am not having any trouble setting the text in the Edit window, my issue is sending the text. All I want to do is be able to send the box a simulated Return key press, but I'm having a lot of issues with it and can't seem to get it to work.
I spied the window and when a real Return is pressed, it generates two messages:
P WM_KEYDOWN nVirtKey:VK_RETURN cRepeat:1 ScanCode:1C fExtended:0 fAltDown:0 fRepeat:0 fUp:0
P WM_KEYUP nVirtKey:VK_RETURN cRepeat:1 ScanCode:1C fExtended:0 fAltDown:0 fRepeat:1 fUp:1
For KEYDOWN, the parameters are:
wParam: 0000000D
lParam: 001C0001
For KEYUP, the parameters are:
wParam: 0000000D
lParam: C01C0001
Given all this information, my current function looks like:
I have had very little success with this method. It will sometimes send the first message it gets but then will no longer send anything. It seems like this should be much simpler, as I'm sure it's a common need. Any help is greatly appreciated.
I spied the window and when a real Return is pressed, it generates two messages:
P WM_KEYDOWN nVirtKey:VK_RETURN cRepeat:1 ScanCode:1C fExtended:0 fAltDown:0 fRepeat:0 fUp:0
P WM_KEYUP nVirtKey:VK_RETURN cRepeat:1 ScanCode:1C fExtended:0 fAltDown:0 fRepeat:1 fUp:1
For KEYDOWN, the parameters are:
wParam: 0000000D
lParam: 001C0001
For KEYUP, the parameters are:
wParam: 0000000D
lParam: C01C0001
Given all this information, my current function looks like:
Code:
void say( const char* toSay )
{
HWND tempa = SetActiveWindow( hwnd );
HWND tempw = SetFocus( chatBox );
Sleep(500);
SendMessage( chatBox, WM_SETTEXT, (WPARAM)0, (LPARAM)toSay );
Sleep(1000);
PostMessage( chatBox, WM_KEYDOWN, VK_RETURN, 0x001C0001 );
Sleep(2000);
PostMessage( chatBox, WM_KEYUP, VK_RETURN, 0xC01C0001 );
Sleep(2000);
SetFocus( tempw );
SetActiveWindow( tempa );
}
I have had very little success with this method. It will sometimes send the first message it gets but then will no longer send anything. It seems like this should be much simpler, as I'm sure it's a common need. Any help is greatly appreciated.