Solved

Prevent KeyDown event from beeping?

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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

A lot of questions regard threads in Delphi.   One of the more specific questions is how to show progress of the thread.   Updating a progressbar from inside a thread is a mistake. A solution to this would be to send a synchronized message to the…
The uses clause is one of those things that just tends to grow and grow. Most of the time this is in the main form, as it's from this form that all others are called. If you have a big application (including many forms), the uses clause in the in…
When you create an app prototype with Adobe XD, you can insert system screens -- sharing or Control Center, for example -- with just a few clicks. This video shows you how. You can take the full course on Experts Exchange at http://bit.ly/XDcourse.
This tutorial demonstrates a quick way of adding group price to multiple Magento products.

760 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