• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1073
  • Last Modified:

Prevent KeyDown event from beeping?

Assuming a Delphi 1 project has a TMemo component on a form...

Why does the following event cause a BEEP to emit from the system speaker?  How does one prevent this beeping?

procedure TForm1.Memo1KeyDown(Sender: TObject; var Key: Word;
  Shift: TShiftState);
begin
      if (Key = 88) and (Shift = [ssAlt]) then {ALT+X}
            Close;
end;
0
Kapusta
Asked:
Kapusta
  • 2
  • 2
1 Solution
 
kjtengCommented:
The beep comes from windows default. Go to control panel to
change it to the sound you like.
Alternatively, you may:
1. drop a button to your form and change its caption to 'E&xit'
2. create an onClick event for the button with the statement:       close
3. Remove your Memo1KeyDown as it is not necessary now
Hope this help

0
 
KapustaAuthor Commented:
>>The beep comes from windows default. Go to control panel to
>> change it to the sound you like.

Thanks, but I'm afraid you missed my point.  I do not want ANY sound event whatsoever.  This application is being distributed to hundreds of people...I surely can't make them change their sound file relationships.

I want NO sound event to occur,...therefore  your suggestion is not acceptable.

As far as your other suggestions...

>> drop a button to your form and change its caption to 'E&xit'

Dropping a button on the current app's interface would destroy the interface.  The app is using custom "fly over" buttons (like Internet Explorer 3.0's buttons) which came from a custom component developed by a third party.  They provide no "hot key" association with these buttons, so I must trap them from the TMemo using a OnKeyDown event.  Adding a plain old Delphi TButton would be redundant.  Sorry, but this solution is not acceptable either.

0
 
rickpetCommented:
The problem is that Delphi is passing an error to the TMemo which is causing the beep.  Normally you would just swallow the offending keystroke on KeyPress...but since your using Alt keys...Keypress is never processed.  So we can't swallow our error in the normal way...ahhh...but there is a workaround...

You say that you are trapping hot key association with TMemo...but there is an easier way grasshopper...

TPopUpMenu...you can associate this with your memo with the PopUpMenu property.  Give it your correct Shortcut...Note you do not need to have the menuitem visible to trap for the hot key.  There is a visible property for the menuitem which you can also set to false.

Rick

0
 
KapustaAuthor Commented:
>>  there is an easier way grasshopper...

Oh great master, thank you for imparting your wisdom upon this child of dust.  Your suggestion, albeit unusual, does indeed work.  Thanks.

0
 
kjtengCommented:
set the button height or width to 1 will hide the button

0

Featured Post

New feature and membership benefit!

New feature! Upgrade and increase expert visibility of your issues with Priority Questions.

  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now