I need to simulate a keypress in a third party application. Let\'s say I have a C# application that needs to send an \"8\" to the Calculator application. I can\'t use the Se
Because it is an Edit Child window inside the notepad window. You should send messages to the right child window. It is a working example in C:
#include
#include
void main(void) {
STARTUPINFO si;
PROCESS_INFORMATION pi;
HWND mainwnd,editwnd;
char c;
si.cb=sizeof(si);
si.lpReserved=NULL;
si.lpDesktop=NULL;
si.lpTitle=NULL;
si.dwFlags=0;
si.cbReserved2=0;
si.lpReserved2=NULL;
if(!CreateProcess("c:\\windows\\notepad.exe",NULL,NULL,NULL,FALSE,0,NULL,NULL,&si,&pi)) {
printf("Failed to run app");
return;
}
WaitForInputIdle(pi.hProcess,INFINITE);
mainwnd=FindWindow(NULL,"Untitled - Notepad");
if(!mainwnd) {
printf("Main window not found");
return;
}
editwnd=FindWindowEx(mainwnd,NULL,"Edit","");
if(!editwnd) {
printf("Edit window not found");
return;
}
for(c='1';c<='9';c++) {
PostMessage(editwnd,WM_CHAR,c,1);
Sleep(100);
}
}