Delphi Alt key + accelerator key plays a "wrong entry" sound

user2383818

I'm coding a custom buttonn derived from tExCustomControl wich, in turn, is derived from tCustomControl. The tExCustomControl component, takes care of painting and has an internal tLabel for caption display (my option for the tLabel was to facilitate the underlying of the accelerator char). In the tExCustomControl, I handle the "keyUp" event like this:

      if Char (Key) = AcceleratorChar then
          if AltKeyIsDown then
              if Assigned (OnClick) then
                 OnClick (Self);

This works fine, except for one thing: while holding down the Alt key and after pressing and realeasing the accelerator key, I get a "wrong entry" sound.

Why is this sound played? How can I avoid this?

Thanks in advance.

Sertac Akyuz

When the Alt key is pressed down while another key is pressed, the system generates a WM_SYSKEYDOWN which is then translated to a WM_SYSCHAR by the TranslateMessage function. The 'beep' is caused by the default processing of this message, which is typically used only for system menu accelerators.

You can prevent further handling of the message to prevent the beep. While you're there, you can process the key too.

procedure tMyExCustomControl.WMSysChar(var Message: TWMSysChar);
begin
  if Message.CharCode = Ord(AcceleratorChar) then
    OnClick(Self)
  else
    inherited;
end;

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related