Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

End "Enter" key press event to a program 1

Status
Not open for further replies.

WilliamCalm

Programmer
Feb 6, 2004
9
CN
Hi, friends:

I want to write a small program that runs at background and simulates a key press event to a running program. To be specific, I need the computer to automaticall press the "enter" key once a minute to the active program window, namely notepad.exe, and in all the process the active window should be notepad.exe. Can anybody tell me how to do that in C, or in VB? Thanks. My OS is Windows 98.

Thanks in advance
 
Here is some code which will find the first "Notepad" program window, find the view window inside it, and simulate a key press by sending it the same window message that it would have gotten if you really did hit the Enter key:

Code:
    HWND notepad = FindWindow ("Notepad", NULL);
    HWND notepadEdit = GetWindow (notepad, GW_CHILD);
    if (notepad && notepadEdit)
    {
        SendMessage (notepadEdit, WM_CHAR, (WPARAM) '\r',
                     (LPARAM) 0x001C0001);
    }
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top