Mirror

How to disable accelerators without ALT (Views: 100)


Problem/Question/Abstract:

I have a tab control with a tab called "Polic&y Info" with the ALT-Y key set to switch to it. If I am on a TCheckBox on any tab and press only the "Y" key, the tab control switches pages.

Answer:

This is nothing specific to a checkbox, it is standard Windows behaviour. If the control having focus does not process character input then ALT is not needed to have a character act as an accelerator. To fix this, add a handler for CM_DIALOGCHAR to your form:

private
{ Private declarations }

procedure cmDialogChar(var msg: TCMDialogChar); message CM_DIALOGCHAR;

procedure TForm1.cmDialogChar(var msg: TCMDialogChar);
begin
  if ((msg.keydata and $20000000) = 0) then
    msg.result := 1 { ALT not down, eat key }
  else
    inherited;
end;

<< Back to main page