devxlogo

Simulating Keystrokes

Simulating Keystrokes

Question:
I am building an add-on application in Visual C++ 6.0. How can you send a key combination (such as Control+K) to another application to invoke a menu shortcut (for example, control+o for open in a file menu)? I can do this in VB using SendKeys, and I wondered how it can be done in VC++.

Answer:
Under Win32, you can use the keybd_event API to send keystrokes to another application. This function is called by the keyboard driver’s interrupt handler when a keystroke is detected so applications will not know the difference between a call to keybd_event and an actual key press.

If you are using NT 4 SP3 or later, you may want to use the newer SendInput function. Please refer to the API reference for additional details.

devxblackblue

About Our Editorial Process

At DevX, we’re dedicated to tech entrepreneurship. Our team closely follows industry shifts, new products, AI breakthroughs, technology trends, and funding announcements. Articles undergo thorough editing to ensure accuracy and clarity, reflecting DevX’s style and supporting entrepreneurs in the tech sphere.

See our full editorial policy.

About Our Journalist