Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8463415
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T14:26:52+00:00 2026-06-10T14:26:52+00:00

I got a notepad which has a PID: 2860 #include <iostream> #include <windows.h> #include

  • 0

I got a notepad which has a PID: 2860

#include <iostream>
#include <windows.h>
#include <psapi.h>
using namespace std;
HWND SendIt (DWORD dwProcessID){
    HWND hwnd = NULL;
    do {
         hwnd = FindWindowEx(NULL, hwnd, NULL, NULL);
         DWORD dwPID = 0;
         GetWindowThreadProcessId(hwnd, &dwPID);
         if (dwPID == dwProcessID) {
            cout<<"yay:"<<hwnd<<":pid:"<<dwPID<<endl;//debug
            PostMessage(hwnd,WM_KEYDOWN,'A',1); //send
         }
    } while (hwnd != 0);
    return hwnd; //Ignore that

}
int main()
{
    SendIt(2680); //notepad ID
    return 0;
}

and notepad should write A to it but nothing happens.
I tried WM_DESTROY message on it and it’s working but WM_KEYDOWN is not working.
I have also done GetLastError() and it prints error 2 ERROR_FILE_NOT_FOUND.

Why is this not working and is it possible to fix it?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-10T14:26:54+00:00Added an answer on June 10, 2026 at 2:26 pm

    PostThreadMessage should be used.

    hThread = GetWindowThreadProcessId(hwnd,&dwPID);  
    if (dwPID == dwProcessID && hThread!= NULL ) {
       PostThreadMessage( hThread, WM_KEYDOWN,'A',1);
    }
    

    Two process must be created by same user. Otherwise, the function fails and returns ERROR_INVALID_THREAD_ID.

    If the other process is active window which is capturing keyboard input, SendInput or keybd_event also can be used to send keystroke event.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I wrote a simple web service in C# using SharpDevelop (which I just got
Has someone got Notepad 6.1.x and HTMLTidy working and can tell me, where to
got some problems. Built an applet that has to be used step-by-step. After each
I open up a notepad from my program using Process.Start() but the new opened
I've got a Windows application (written in C, compiled with MSVC Express edition, 32-bit
I'm writing my filesystem using C# and Dokan library and got stuck on WriteFile.
I'm trying out Git on Windows . I got to the point of trying
I got to try an exercise 1 of notepad application just yesterday and passed
I just got done reviewing the Notepad tutorial and looking at how they do
Got a bluescreen in windows while cloning a mercurial repository. After reboot, I now

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.