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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T03:24:41+00:00 2026-05-27T03:24:41+00:00

I want to send some keystroke to the external application, and it’s work fine,

  • 0

I want to send some keystroke to the external application, and it’s work fine, but when I try to send keystroke to the child window of same external application, for some reason that doesn’t work, so I need help. Let’s say that we want to print clipboard text from notepad, and want to do it at one step. At code that will look like this.

        #include <windows.h>
    #include <stdio.h>
    #include <iostream.h>
    using namespace std;

    int main(int argc, char* argv[]){
        WinExec("notepad", 1);
        Sleep(1000);
        HWND handle = FindWindow("notepad",0);  // it's handling as well
        SetForegroundWindow(handle);        
        keybd_event(VK_CONTROL, 0, 0, 0);   // simulate CTRL down
        keybd_event(VkKeyScan('V'), 0, 0, 0);
        keybd_event(VK_CONTROL, 0, KEYEVENTF_KEYUP, 0); 
        Sleep(500);
        keybd_event(VK_CONTROL, 0, 0, 0);   // simulate CTRL down
        keybd_event(VkKeyScan('P'), 0, 0, 0);
        keybd_event(VK_CONTROL, 0, KEYEVENTF_KEYUP, 0); // simulate CTRL up
        Sleep(1000);
        HWND handle1 = FindWindow(0, "Print");  // it wann't find "Print" window
        SetForegroundWindow(handle1);
        keybd_event(VK_MENU, 0, 0, 0); // simulate ALT down
        keybd_event(VkKeyScan('P'), 0, 0, 0);
        keybd_event(VK_MENU, 0, KEYEVENTF_KEYUP, 0);
        return 0;
    }

But it want to send ALT+P to “Print” window, why?
Final goal is to make little macro that send to application keystorkes (on any windows child, or parent..)
OS: WIN 7 64bit

  • 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-27T03:24:42+00:00Added an answer on May 27, 2026 at 3:24 am

    You can probably make the existing code (sort of) work by simply removing these lines:

    HWND handle1 = FindWindow(0, "Print");  // it wann't find "Print" window
    SetForegroundWindow(handle1);
    

    Remember that faked input goes to the thread which has the input focus and when you show the print dialog in Notepad, that dialog will gain the input focus. You simply do not need to set the focus, the system will do that for you.

    However, the approach you are taking is incredibly brittle. I suspect that you would be far better served by using something like UI Automation.

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

Sidebar

Related Questions

My application needs to send some packets every 30 minutes, but I don't want
Want to send the text from my current vb application to the Active Window
In my web application I want to send some text back in the addActionError(User
In my application i want to send mail to some one. If i use
I want to send some values from my iPhone application to an ASp.Net web
i want to send some html in email body, but gmail doesn't interpret iframe
I want to send and receive some data from my server, but I don't
I've got an application which i want to send some alerts information. Currently, it's
I want to send some text value to my custom popup window when it
In my application I want to send some alerts to the client. I want

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.