Solved

Prevent KeyDown event from beeping?

Posted on 1998-05-25
5
1,007 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

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…
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…
Along with being a a promotional video for my three-day Annielytics Dashboard Seminor, this Micro Tutorial is an intro to Google Analytics API data.
In this video I am going to show you how to back up and restore Office 365 mailboxes using CodeTwo Backup for Office 365. Learn more about the tool used in this video here: http://www.codetwo.com/backup-for-office-365/ (http://www.codetwo.com/ba…

911 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

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now