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 7703721
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T23:31:24+00:00 2026-05-31T23:31:24+00:00

I want to send keystrokes to multiple processes. For example, if I press 1,

  • 0

I want to send keystrokes to multiple processes. For example, if I press “1”, then I want to send the “1” to 3 “Notepad windows”. Frist I want to try to send a keystroke to notepad, but it fails on the HWND:

    //HANDLE hWin; 
    HWND windowHandle = FindWindowA(NULL, "Notepad");   //Can’t find a proccess

    //Send a key
    if( windowHandle ) //This one fails
    {
        while(true)
        {
            if( GetAsyncKeyState(VK_F12) != 0 )
            {
                SendMessageA(windowHandle, WM_KEYDOWN, VK_NUMPAD1, 0); 
                Sleep(1000); 
                SendMessageA(windowHandle, WM_KEYUP, VK_NUMPAD1, 0);
            }
                    Sleep(100);
        }
    }

But the “FindWindow” method is not good enough for my program. There is also no way to get 3 different processes with the same name. So how can I make 3 handles to 3 different processes with the same name? And how can I send key’s to the processes?

  • 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-05-31T23:31:25+00:00Added an answer on May 31, 2026 at 11:31 pm

    You can use EnumWindows for enumerating all the top level windows on the system. You then need to filter through these windows to get the ones you are interested in. Class name is probably a better choice for filtering rather than the window name though. Here is some example code (not tested) of what I have in mind:

    BOOL CALLBACK BroadcastToNotepad(HWND hwnd, LPARAM lParam)
    {
        wchar_t lpClassName[16];
    
        /*
         * More reliable to filter by class name. We could additionally filter
         * by caption name too if necessary.
         */
        if(GetClassName(hwnd, lpClassName, _countof(lpClassName))) {
            if(wcscmp(lpClassName, L"Notepad") == 0) {
                SendMessage(hwnd, WM_KEYDOWN, (WPARAM)lParam, 0);
                Sleep(1000);
                SendMessage(hwnd, WM_KEYUP, (WPARAM)lParam, 0);
            }
        }
    
        return TRUE;
    }
    
    // Some handler which gets invoked when your hotkey is hit.
    void handlerKey1(...)
    {
        EnumWindows(BroadcastToNotepad, (lParam)VK_NUMPAD1)
    }
    

    Note the usage of BroadcastToNotepad and how you can have different handlers pass in a different lParam.

    One final thing to note is that PostMessage/SendMessage is not a reliable way to simulate keyboard input. This is noted by Raymond Chen here. SendInput is the preferred way for injecting input. However, to use that you will need to ensure the window you want to send to has the keyboard focus.

    I recall vaguely having played with something similar to what you are doing in the past. If I remember correctly, you need to send to Notepad’s child window (class name = Edit). So the code above needs to be modified as so:

    if(wcscmp(lpClassName, L"Notepad") == 0) {
        HWND hwndChild = FindWindowEx(hwnd, NULL, L"Edit", NULL);
    
        SendMessage(hwndChild, WM_KEYDOWN, (WPARAM)lParam, 0);
        Sleep(1000);
        SendMessage(hwndChild, WM_KEYUP, (WPARAM)lParam, 0);
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to send a keystroke to a GLUT program on X11, but I
im using keybd_event(); and i want use SendMessage(); to send keystroke to notepad, can
I want so send every week an update by email. But Im afraid that
if i want send email with SwiftMailer in symfony then i must in action:
Is it possible to send keystrokes to a cocoa app? I don't want to
I want to send some keystroke to the external application, and it's work fine,
I want send a email by Email Class in codeigniter with gmail, but i
For testing purposes I want send mail to my localhost user account rather than
Want to send the text from my current vb application to the Active Window
I want to send email from a Ruby application. Is there a call in

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.