
October 31st, 2002, 08:31 AM
|
 |
Junior Member
|
|
Join Date: Oct 2002
Posts: 2
Time spent in forums: < 1 sec
Reputation Power: 0
|
|
|
Passing fake keystrokes to a third part application
This is what I've been able to learn so far with regard to sending keystrokes from my c program to a third part executable application. In summary I basically get the handle to the application and simply send it a message using that handle and the message format is determined by the output captured using a handy application spy.exe that can be found in the MS SDK distribution. This message is repeated by my code but nothing happens in the third party application. For some reason unknown (and undocumented by M$) it simply does not respond. My guess is that it has to do with the handle of the message sender and I have to assume that it is a handle (00170448) that's in front of spy's output because it's not described in the M$ documentation as well. The only difference I can see is the handle/ID being different and the keydown capture handle in the capture sequence is different.
So if anyone can help me to make some progress beyond this, please let me know, any suggestions or ideas welcomed!
Code:
/*
captured code
00170448 WM_KEYDOWN 00000011 001D0001
00170448 WM_KEYDOWN 00000053 001F0001
00170448 WM_CHAR 00000013 001F0001
00050514 WM_KEYUP 00000053 C01F0001
00050514 WM_KEYUP 00000011 C01D0001
result of my program code
0019044E WM_KEYDOWN 00000011 001D0001
0019044E WM_KEYDOWN 0000004F 00180001
0019044E WM_CHAR 0000000F 00180001
0019044E WM_KEYUP 0000004F C0180001
0019044E WM_KEYUP 00000011 C01D0001
*/
#include "windows.h"
#include "toolbox.h"
#include <ansi_c.h>
#include <utility.h>
#include <cvirte.h>
int __stdcall WinMain (HINSTANCE hInstance, HINSTANCE hPrevInstance,
LPSTR lpszCmdLine, int nCmdShow)
{
int ExeHandle;
HWND WindowHandle;
LRESULT Result;
WPARAM WParam;
LPARAM LParam;
//launch my application here
LaunchExecutableEx ("Notepad.exe WinMSG.txt", LE_SHOWNORMAL,&ExeHandle);
//wiat a while before getting the handle else it return NULL
Delay(1);
//get the handle to the application
WindowHandle = FindWindow(
"Notepad", //LPCTSTR lpClassName - class name
"WinMSG.txt - Notepad"//LPCTSTR lpWindowName - window name
);
//Key sequence captured with Spy.exe - what happens when you hit <ctrl>S in
//a notepad window and you get the save dialogue
/*
00170448 WM_KEYDOWN 00000011 001D0001
00170448 WM_KEYDOWN 00000053 001F0001
00170448 WM_CHAR 00000013 001F0001
00050514 WM_KEYUP 00000053 C01F0001
00050514 WM_KEYUP 00000011 C01D0001
*/
//This code produces the exact same results in spy, but no result in notepad
WParam=0x11;
LParam=0x1D0001;
Result = SendMessage(WindowHandle,WM_KEYDOWN,WParam,LParam);
WParam=0x4F;
LParam=0x180001;
Result = SendMessage(WindowHandle,WM_KEYDOWN,WParam,LParam);
WParam=0xF;
LParam=0X180001;
Result = SendMessage(WindowHandle,WM_CHAR,WParam,LParam);
WParam=0x4F;
LParam=0xC0180001;
Result = SendMessage(WindowHandle,WM_KEYUP,WParam,LParam);
WParam=0x11;
LParam=0xC01D0001;
Result = SendMessage(WindowHandle,WM_KEYUP,WParam,LParam);
Delay(5);
TerminateExecutable (ExeHandle);
RetireExecutableHandle (ExeHandle);
return 0;
}

Last edited by jattie : October 31st, 2002 at 08:34 AM.
|