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

Memo Question

Hi,

I have this code:

  if (Key = Ord('B')) and (ssCtrl in Shift) then
    BoldBtn.Click;

in the Keydown Event. I want to get rid of the short sound when pressing CTRL + one key in the memo.

Thanks,
0
crystyan
Asked:
crystyan
  • 6
  • 5
  • 4
  • +1
2 Solutions
 
Scay7Commented:
what does
boldbtn.click;
do because usually when you call another procedure its
boldbtnclick(sender);
well not sure cause not sure where that procedure points to

if i put that procedure into my downkey avent in the memo like:

procedure TForm1.Memo1KeyDown(Sender: TObject; var Key: Word; Shift: TShiftState);
begin
if (Key = Ord('B')) and (ssCtrl in Shift) then
    showmessage('test');
end;

I get no beep or beeps so mabey its in the boldbtn.click; story...

Peace Scay7
0
 
crystyanAuthor Commented:
HI,

I still get the beep on showmessage too ...

Thanks
0
 
TheRealLokiSenior DeveloperCommented:
put
Key := 0 at the end

procedure TForm1.Memo1KeyDown(Sender: TObject; var Key: Word; Shift: TShiftState);
begin
if (Key = Ord('B')) and (ssCtrl in Shift) then
    begin
        Key := 0;
        showmessage('test');
    end;
end;
0
Independent Software Vendors: 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!

 
Scay7Commented:
Does the beep come from the system speaker (the box)
or from the desktop speakers ?

Scay7
0
 
crystyanAuthor Commented:
from the desktop speakers ... where I hear the music lol.
0
 
Scay7Commented:
Did you try what loki said... then otherwise its the windows notification beep :P

Peace Scay7
0
 
crystyanAuthor Commented:
yeah lol ... it`s the windows notification beep ... that`s what I wanted to get rid of :-) it`s like when u are trying to write into an edit box more than the maximum number of chars allowed.
0
 
TheRealLokiSenior DeveloperCommented:
happens anytime i capture the KeyDown message
e.g
if Key = vk_Return then
begin
//domsomething
    key := 0;
end;
If I don't put the key = 0 at the end, i get a beep :-)
0
 
crystyanAuthor Commented:
nope, still have the prob ..
0
 
TheRealLokiSenior DeveloperCommented:
change your code from
BoldBtn.Click; to BoldBtnClick(BoldBtn);
0
 
crystyanAuthor Commented:
it`s not that ... it happens anytime I press CTRL + a key ... it`s something from OnKeyDown event ...
0
 
Scay7Commented:
Lol go to system sounds and select (no sounds) problem solved :P

or write in a mute option :P for the master sound... volume
http://www.swissdelphicenter.ch/torry/showcode.php?id=1630
or
http://www.delphifaq.com/faq/delphi_windows_API/f522.shtml

Peace Scay7
0
 
crystyanAuthor Commented:
looool

can`t do that ... :-) so the user will mute the system if they keep CTRL + B pressed !?

:-))))))
0
 
TheRealLokiSenior DeveloperCommented:
lol ok, dunno.
but 1 way around it is to do the following
put a TActionList on the form (Standard tab on component palette), and make an action in it, call it "aBold" for example
set it's "Shortcut" to CTRL+B
set the event code in there to do BoldBtnClick(BoldBtn);

remove your keydown code for ord('B') etc..
you wont have a beep, and "bold" can be done from anywhere
if you only wish it to be active in that edit box, use the OnEnter andOnExit events of the TEdit to do
aBold.Enabled := False/True

hth, Loki... stupid beeping... I should know how to stop it, but my mind's a blank
0
 
TheRealLokiSenior DeveloperCommented:
some more info from the www....

The beep is made by the DefWindowProc for keys which is not handled by the
text box. Your code doesn't work because beep is produced in responce to
WM_CHAR (KeyPress), I believe. However you have options.
1. you can override TextBox and its WndProc method and process WM_CHAR
message without passing it to the DefWindowProc
-or-
2. Add a main menu item or TAction(inTActionList) (it can be hidden) with shortcut for Ctrl+B
and handle the key press there.
-or-
3. Handle KeyPress instead of key down. e.Handled works for this event. For
Ctrl+Shift+E key press is fired only for Ctrl+E (ASCII 5) so, you have to
check for Shift yourself.


to do the 3rd option, and work out shift, you can use this routine

Get Shift/ Ctrl/ Alt Key state
This code determines the state of shift, alt and ctrl keys.
You can do this while your application is initializing, in order to do something or not to do something.

{ Tests whether the high order bit of the given word is set.     }
function HighOrderBitSet (theWord: Word): Boolean;
const
  HighOrderBit = 15;
type
  BitSet = set of 0..15;
begin
  HighOrderBitSet := (HighOrderBit in BitSet(theWord));
end;

..
begin
  ..
  AltKeyDown := HighOrderBitSet(Word(GetKeyState(VK_MENU)));
  CtrlKeyDown := HighOrderBitSet(Word(GetKeyState(VK_CONTROL)));
  ShiftKeyDown := HighOrderBitSet(Word(GetKeyState(VK_SHIFT)));
  ..
end.
 
0
 
atul_parmarCommented:
Hi, Here is some workaround

introduct a type.
eg.
type
  TBuffers = array [0..255] of TKeyboardState;

create a procedure
procedure Test;
begin
  Form1.BoldBtn.Click;
end;

Change your OnKeyDown to look like the following:

var
  pKeyBuffers: ^TBuffers;
  MyKey : Word;
begin
  If ((GetKeyState(VK_LCONTROL) and 128) = 128)
  or ((GetKeyState(VK_RCONTROL) and 128) = 128) then
  begin
    MyKey := Key;
    SetKeyboardState(pKeyBuffers^[0]);
    if (Key = Ord('B')) then
      Test; // Calling test procedure as it calls your BoldBtn.Click.
  end;
end;

I surprised, if you I call your BoldBtn.Click inside Test procedure it doesn't beeps but I place it inside the OnKeyDown it beeps. Anyway This fixes your problem so I don't want to pull my hair in knowing why it behaves so.
0

Featured Post

How to Use the Help Bell

Need to boost the visibility of your question for solutions? Use the Experts Exchange Help Bell to confirm priority levels and contact subject-matter experts for question attention.  Check out this how-to article for more information.

  • 6
  • 5
  • 4
  • +1
Tackle projects and never again get stuck behind a technical roadblock.
Join Now