Re: How can I stop controls from executing default keyboard and mouse behavior?

From: Maarten Wiltink (maarten_at_kittensandcats.net)
Date: 01/29/04


Date: Thu, 29 Jan 2004 20:50:32 +0100


"IDF" <idf@nospam.nospam> wrote in message
news:aI5Sb.7462$sV7.5136@newssvr29.news.prodigy.com...

> I keep running into the same problem; controls seem to have a built-in
> action they take with regard to certain keyboard and mouse events, that
> at times I want to disable. ...

No, you don't. There is such a thing as consistency in user interface.
When Windows generally behaves in a certain way, you should follow it,
if only because users will expect your program to behave in that way,
too.

[...]
> could not stop the TJvStringGrid (which usually has focus) from
> responding to the PgUp and PgDn keys which were always detected and
> acted upon even if the Ctrl keys were also being pressed. The grid
> scrolls itself when arrows, page keys, home and end are pressed.

Okay, so that control is badly written. Get a better one.

[...]
> A TJvSpinEdit. It increments and decrements itself with no event handler
> needed if you press up arrow or down arrow when it has focus.

Okay.

> But I also have some form-level keyboard handling that increments/
> decrements the spin control if you use the arrow keys regardless of
> focus, so you don't have to explicitly select the spinedit or press
> the tiny spin edit scroller buttons.

Not okay. Although there are exceptions aplenty, most controls should
not react to the keyboard when they don't have the focus. What do you
do when you have two spinedits? You have only one keyboard focus.

Put a label with an accelerator key next to the spinedit. The mechanism
is there; all you have to do is use it.

[...]
> A TCheckListBox. I liked seeing the checkboxes for multi-selection,
> but I hated having to click in the itty bitty little checkboxes - I
> wanted to be able to click anywhere on the row to flip (set or clear)
> the selection.

So Ctrl-Click like everybody else. Doesn't even require a checklistbox;
a normal multiselect listbox will do fine. Ctrl-Space works, too, and
Ctrl-Up and Ctrl-Down for moving the focus without changing selections.

[...]
> The general problem is controls executing built-in behavior that I
> can't disable or take control of.

No, the general problem is that you think you must cut your own way
through the jungle.

> Now, I have some other problems: that form-level arrow key handling I
> described above is causing problems, ...

I'm not surprised. Lose it altogether and you will have fewer problems.

> [...] left arrow and right arrow, which I'm using as synonyms for two
> particular buttons (a previous and next button on the form)?

Well, Leonardo, Don't Do That, Then. Study the effect of ampersands
in button captions, and try to get your users to look at the screen,
not the keyboard, and either use Alt-Period and Alt-Comma for Back and
Forth, or Alt-N and Alt-B (because it's "Back", not "Previous", in
wizards). And don't forget about Space and Enter. I cringe every time I
see people laboriously use the mouse to click on OK buttons.

I get to cringe a lot.

[...]
> These workarounds are getting a bit much, and can't be the right
> approach; maybe I have the wrong philosophy and am trying too hard
> to make Windows behave in non-standard ways.

Hold that thought. Writing your own window manager is for X folks.

Groetjes,
Maarten Wiltink