Solved

Prevent KeyDown event from beeping?

Posted on 1998-05-25
5
1,012 Views
Last Modified: 2012-05-07
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
Comment
Question by:Kapusta
  • 2
  • 2
5 Comments
 
LVL 2

Expert Comment

by:kjteng
ID: 1347871
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
 

Author Comment

by:Kapusta
ID: 1347872
>>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
 
LVL 3

Accepted Solution

by:
rickpet earned 50 total points
ID: 1347873
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
 

Author Comment

by:Kapusta
ID: 1347874
>>  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
 
LVL 2

Expert Comment

by:kjteng
ID: 1347875
set the button height or width to 1 will hide the button

0

Featured Post

Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

This article explains how to create forms/units independent of other forms/units object names in a delphi project. Have you ever created a form for user input in a Delphi project and then had the need to have that same form in a other Delphi proj…
Have you ever had your Delphi form/application just hanging while waiting for data to load? This is the article to read if you want to learn some things about adding threads for data loading in the background. First, I'll setup a general applica…
This Micro Tutorial demonstrates using Microsoft Excel pivot tables, how to reverse engineer competitors' marketing strategies through backlinks.
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…

776 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question