|Subject:||How to avoid Treeview beeps when handling special keys|
|Posted by:||Gerrit Beuze (gerrit[at][-nospam]modelmakertools[dot]com)|
|Date:||Fri, 25 Jul 2008|
I'm (optionally) handling a few Ctrl+Key combinations in a TTreeview descendant
like Ctrl+A = select all.
Implemented basically like:
procedure TTreeViewEx.KeyDown(var Key: Word; Shift: TShiftState);
if (Shift = [ssCtrl]) and (Key = Ord('A') then
Key := 0;
inherited KeyDown(Key, Shift);
procedure TTreeViewEx.KeyPress(var Key: Char);
// Avoid beep
if (Key = 'A') then
// This breakpoint never gets hit
if (KeyboardStateToShiftState = [ssCtrl]) then
Key := #0;
This works fine, however, my normal technique to suppress the beep for unhandled keys
using KeyPress to clear the key does not work: the treeview beeps anyway.
In fact: setting a breakpoint after the if Key = 'A' line never hits.
I tried several other methods: override WMChar, WMKeyPress. Nothing works.
Thanks in advance,