RE: Block mouse and keyboard input

Tech-Archive recommends: Speed Up your PC by fixing your registry

From: Tyler Laing (TylerLaing_at_discussions.microsoft.com)
Date: 12/11/04


Date: Fri, 10 Dec 2004 17:29:02 -0800

I solved my problem if anyone is interested, here are the steps:

1) Add an implementation of IMessageFilter that filters out mouse and
keyboard messages

2) Call PlaySound with synchronous flag set

3) When sound is done, send a keyboard event via method keybd_event(...)
using a virtual key id that is undefined (therefore should never be sent from
physical key presses)

4) IMessageFilter implementation also watches for the undefined virtual key
id and stops filtering once received.

This works because the simulated KEY_DOWN message is queued up behind all
the actual keyboard and mouse message that happen while the sound is playing.

Might be slightly hacky, but it works marvelously.

"Tyler Laing" wrote:

> I would like to block input to prevent controls like buttons from being
> pressed for a short period of time while a sound is playing.
>
> While my app is doing something like playing a sound synchronously, the user
> can press buttons or other controls. These mouse events are queued up and
> then my message pump processes them *after* the sound is done playing.
>
> In this scenario, a user can press a button with the stylus but the program
> won't act on it until several seconds later (depending on the duration of the
> sound). This behavior is unwanted. Rather, it is preferred that such button
> presses are ignored, which is preventable by blocking/filtering mouse and
> keyboard input.
>
> I have tried a couple of various methods but each one comes with its own
> downfall and none have fully solved this problem.
>
> What I would really like is to be able to make a call that tells the OS to
> stop sending my application input messages, and then a call to tell the OS to
> start sending them again. Any input between the two calls would be blocked
> from making it to my application. There appears to be a BlockInput(bool) call
> that does just this, but it's not supported in Windows CE as far as I can
> tell.
>
> NOTE: I am NOT trying to block CTRL+ALT+DEL or any other system key combos.
> Just trying to block regular input, and thus preventing control events.


Quantcast