Briefly suspending keyboard input?
From: Martin Kochanski (nothing_at_nobody.net)
Date: 03/23/04
- Next message: Julius: "Scan codes for F13, ..., F24"
- Previous message: Dean Roddey: "Re: How to get around new limitations on SetForegroundWindow()?"
- Next in thread: William DePalo [MVP VC++]: "Re: Briefly suspending keyboard input?"
- Reply: William DePalo [MVP VC++]: "Re: Briefly suspending keyboard input?"
- Messages sorted by: [ date ] [ thread ]
Date: Tue, 23 Mar 2004 08:50:03 +0000
My application implements certain user commands by communicating with a
server. This means that it sends a command and waits until the server
has responded: it waits either in a message loop of its own or by
falling back into the main application message loop.
One example: when you press Ctrl+E to start editing, a request for
permission goes to the server, and the application waits for this
permission to be granted before continuing.
The user is often unaware of these delays, which are short.
My problem is that keystrokes that arrive during the "wait for server"
loop are retrieved by GetMessage before the application is properly
ready to receive them, which means (at the moment) that they are
discarded. This is not good for the user, who wants every keystroke to
go to its correct place without having to glance at the screen the whole
time.
I'm wondering whether other people have had this kind of problem and how
they have sorted it out. Essentially, I just want to suspend keyboard
input during the wait. Here are a few approaches I've considered: any
advice or comment would be welcome.
1. Cache all the WM_KEYDOWN and WM_KEYUP messages received by GetMessage
(either in GetMessage itself or using a WH_KEYBOARD hook) and
PostMessage them out after the wait has completed. One problem I can see
here is focus: some keystrokes may call up a dialog box, so I won't know
which window to post each key to. I note that keybd_event or SendInput
could be used, but is it hard to synthesize the data required by those
functions from the cached WM_KEYDOWN/UP messages?
2. Replace all occurrences of GetMessage with a pair of PeekMessage
calls that carefully avoid the keyboard range. This seems messy and I'm
not sure I'll be able to isolate every occurrence in this way.
Any other approaches I haven't considered? Any experience to share?
A sting in the tail: it would be good to allow Esc to cancel the wait
and purge any queued keystrokes.
- Next message: Julius: "Scan codes for F13, ..., F24"
- Previous message: Dean Roddey: "Re: How to get around new limitations on SetForegroundWindow()?"
- Next in thread: William DePalo [MVP VC++]: "Re: Briefly suspending keyboard input?"
- Reply: William DePalo [MVP VC++]: "Re: Briefly suspending keyboard input?"
- Messages sorted by: [ date ] [ thread ]
Relevant Pages
|