How to synthesize a keystroke

How to synthesize a keystroke

I have a Quickwin program that calls GETCHARQQ to read a keystroke. Unlike PEEKCHARQQ (which can only be used in console apps), it blocks execution until user presses a key. In certain program-determined circumstances, I need execution to continue without a user response. My idea is to have the program "put" a character into the keyboard "buffer" (perhaps not the right term) so that GETCHARQQ will respond and continue on its merry way.

Is there any way to do this? The nearest thing I can find is the API function SendInput. It looks like this is just what I need, but I am not enough of a C++ programmer to understand the documentation or how to implement it. Can anybody help?

5 posts / 0 new
Last post
For more complete information about compiler optimizations, see our Optimization Notice.

Since the program is blocked, how are you going to get control to insert the character?

Steve - Intel Developer Support

Here's what I'm hoping (but I could be all wet):
The program has a mouse event registered (mouse$move). While blocked awaiting a keystroke (such as 'y' to answer a pending question), the user will (presumably) move the mouse to click on a 'yes' button as an alternative to pressing 'y'. The registered callback routine responds to the mouse movement and detects whether the mouse is positioned over the button. So far so good; I have this much working. Now if the callback routine can write a character to the keyboard buffer, it will allow the GETCHARQQ to free its blocking.

I know that another way to accomplish this is to start a second thread; one thread watches for keystrokes while another watches for mouse movement. But that seems more complicated to me than the approach described above.

I wrote a program that uses SendInput, but QuickWin doesn't see the keystrokes. I think the way you'd have to do this is with subclassing, as the POKER sample does, to intercept the keystroke. I checked with our QuickWin developer and he could not think of a way to do this offhand.

Steve - Intel Developer Support

Thanks for the try Steve. I was afraid that might be the case. You probably saved me a couple of hours of effort. I think I'll pursue the two-threads technique, as suggested in the documentation and the sample program PeekApp or PeekApp3.

Leave a Comment

Please sign in to add a comment. Not a member? Join today