Button swallows keys. Bug? Workaround?

  • Thread starter Thread starter Felix
  • Start date Start date
F

Felix

The Setup:
================
I have a cardswiper attached to my keyboard, so that when I swipe a
card I get "keyboard input" that looks something like:
%748a45a1246fbac9d8fdeaf3572f221b?

I would like forms in my application to handle these card swipes. To
this end, I've made a base Form that sets KeypPeview=true, and that
overrides the ProcessDialogKey method.

The Bug:
==========
This setup works well, except in a few circumestances. One common
circumstance is if I have buttons with shortcuts (e.g. a button whose
Text attribute is "&add member". Here "a" is a shortcut.

I have noticed that if any button on the form has the focus, then "a"
is consumed by the button and does not make it to ProcessDialogKey. If
something else (like a listbox) has the focus, then I do receive the
key in ProcessDialogKey.

Does anyone have a solution, an idea, or a workaround?

Thanks in advance!

Felix
 
IMHO the KeyPreview property isn't very good
Try using IMessageFilter and handle WM_KEYDOWN
messages.

/claes
 
This was some good advice. Thanks Class!

Here is one problem (which I have a workaround for):

I get WM_KEYDOWN, WM_CHAR, WM_KEYUP events for each keystroke. Let's
say I consume WM_KEYDOWN if they match some pattern. WM_KEYUP events
are still fired. This works fine except in the case of a SPACE, since
buttons fire on a WM_KEYUP.

I can just consume WM_KEYUP spaces, but this seems like a hack. Any
ideas?

Also, what is the best way to convert WM_KEYDOWN to an ascii char?

Thanks again!

Felix
 
This was some good advice. Thanks Class!

Here is one problem (which I have a workaround for):

I get WM_KEYDOWN, WM_CHAR, WM_KEYUP events for each keystroke. Let's
say I consume WM_KEYDOWN if they match some pattern. WM_KEYUP events
are still fired. This works fine except in the case of a SPACE, since
buttons fire on a WM_KEYUP.

FYI, WM_CHAR will only be sent if the WM_KEYDOWN results in a printable
character (you won't get it for the Delete key for instance)
I can just consume WM_KEYUP spaces, but this seems like a hack. Any
ideas?

That's the way I would do it (I'm assuming you're using a flag that
you set in WM_KEYDOWN)
Also, what is the best way to convert WM_KEYDOWN to an ascii char?

I don't think there is a way. If you need the ASCII char use WM_CHAR
instead.


/claes
 
Back
Top