How to invoke the. NET Framework from an MFC application

Source: Internet
Author: User

How do I send keystrokes to other applications?

about how to programmatically send Ctrl+alt+del keystrokes?

How do I invoke the. NET framework from an MFC application?

I want to write an application that can write information to a form in another application by clicking the key. Should I send wm_keydown and wm_keyup messages? Is there a better way?

Sending Wm_keydown and WM_KEYUP messages may work, but SendInput is a specially designed API function for this purpose. It uses input structure array parameters to synthesize inputs including keystrokes and mouse events, and each input structure array element corresponds to an entry event-keystroke or mouse action. The INPUT structure contains a union type whose members are Mouseinput,keybdinput (or hardwareinput, emulated bread ovens). For keystrokes, the keybdinput structure is as follows:

struct KEYBDINPUT {
WORD wVk;   // virt key code
WORD wScan;  // hw scan code
DWORD dwFlags; // flags—see doc
DWORD time;  // time stamp, 0 = dflt
ULONG_PTR dwExtraInfo; // app-defined
};

So sending a keystroke to another application is actually creating an INPUT array with each array element corresponding to a keystroke (bouncing and pressing) and then calling the SendInput function. In order to demonstrate its actual use, I wrote a small program called typematic, you just press a hot key, you can quickly put your name, address, phone number or other information into the form. This is an ideal thing for online shoppers. When you run Typematic for the first time, the dialog box shown is shown in Figure 1:

Figure 1 typematic Initial dialog box

Press the "OK" button to enter the hidden state. You can then press <winkey>+t to reactivate the typematic, displaying the dialog box shown in Figure 2:

Figure 2 is reactivated typematic.

You can see that the dialog box shows a list of abbreviated information. Type "n" to represent the name, "a" represents the address, and Typematic sends the corresponding string to the current form or application. These abbreviations are defined in a static table, and you can change them to your own information:

struct ABBREV {
TCHAR key;
LPCTSTR text;
} MYABBREVS[] = {
{ _T(''n''),_T("Elmer Fudd") },
{ _T(''a''),_T("1 Bunny Way") },
...
{ 0,NULL}
};

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.