?
Solved

Prevent KeyDown event from beeping?

Posted on 1998-05-25
5
Medium Priority
?
1,041 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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 150 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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

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…
Introduction I have seen many questions in this Delphi topic area where queries in threads are needed or suggested. I know bumped into a similar need. This article will address some of the concepts when dealing with a multithreaded delphi database…
Visualize your data even better in Access queries. Given a date and a value, this lesson shows how to compare that value with the previous value, calculate the difference, and display a circle if the value is the same, an up triangle if it increased…
How to fix incompatible JVM issue while installing Eclipse While installing Eclipse in windows, got one error like above and unable to proceed with the installation. This video describes how to successfully install Eclipse. How to solve incompa…
Suggested Courses
Course of the Month15 days, 6 hours left to enroll

770 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