void KeyPress(int key, char* pWndName) { HWND hWnd = ::FindWindow(NULL, pWndName); if (hWnd) { ::SetForegroundWindow(hWnd); ::SendMessage(hWnd, WM_KEYDOWN, key, 0); ::SendMessage(hWnd, WM_KEYUP, key, 0); } else MessageBox(NULL, "Window not found", NULL, NULL); }