Thanks
Mike
procedure TForm1.FormKeyDown(Sender: TObject; var Key: Word;
Shift: TShiftState);
??
Mine has shift
So,
if (ssctrl in shift) and (chr(key)='F') then showmessage('Ctrl+F
detected');
same with keyup
set the key to 0 to cancel its action.
Yeah, my keydown declaration is the same, and I know how to test the
shiftstate, but how do I prevent the beep? That was the question.
>
>set the key to 0 to cancel its action.
I tried this and the beep still occurs.
Mike
> I tried this and the beep still occurs.
Well ctrl+F doesnt cause a beep by default, so, what exactly is causing
the beep? normally the beep is pressing enter..
>> I tried this and the beep still occurs.
>
> Well ctrl+F doesnt cause a beep by default, so, what exactly is causing
> the beep?
eating the keydown. <g>
He'll have to eat ctrl-F in keyup too.
if you were told someone had come back in when as far as you knew they
hadn't gone out, wouldn't you beep too? %).
>Well ctrl+F doesnt cause a beep by default, so, what exactly is causing
>the beep? normally the beep is pressing enter..
It looks to me like the Ctrl-F is causing the beep. It is a WM_CHAR
message that gets dispatched and then some assembly code results in
the beep. What else do I need to look at?
Mike
Mike
> In searching more, I found that if I enter any Ctrl + SomeChar in any
> control that has focus such as an edit box in a modal form, I get a
> beep. What is causing this?
That's just standard windows behavior. It's letting the user know that
they pressed a key that didn't actually do anything useful. You'll
notice this if you simply create a new project in Delphi and drop a
tEdit on it. Ctrl+F will cause a beep. Ctrl+A will cause a beep.
Ctrl+C, Ctrl+X, Ctrl+V, etc. will not cause a beep since those
keystrokes are consumed at a lower level for clipboard operations.
--
-Mike (TeamB)
In searching more, I found that if I enter any Ctrl + SomeChar in any
control that has focus such as an edit box in a modal form, I get a
beep. What is causing this?
Mike
>>Well ctrl+F doesnt cause a beep by default,
Hmm, take that back Liz!
I agree with the next para, at least if somechar is 'F'. (or ABDEGI...)
> In searching more, I found that if I enter any Ctrl + SomeChar in any
> control that has focus such as an edit box in a modal form, I get a
> beep.
So they do.
Most of my edits have a restriction of some kind in OnKeyPress, which says
what chars I will allow (e.g. numbers) so they don't beep as ctrl-F is not a
number.. so clearly eating it here works.
Despite what it says in help on OnKeyPress about handling extended chars in
OnKeyDown I'd expect therefore that an OnKey*Press* handler reading
if key=chr(6) then key:=chr(0);
would suppress Ctrl-F.
> What is causing this?
.. what Mike W. says. %).
>That's just standard windows behavior. It's letting the user know that
>they pressed a key that didn't actually do anything useful. You'll
>notice this if you simply create a new project in Delphi and drop a
>tEdit on it. Ctrl+F will cause a beep. Ctrl+A will cause a beep.
>Ctrl+C, Ctrl+X, Ctrl+V, etc. will not cause a beep since those
>keystrokes are consumed at a lower level for clipboard operations.
That makes sense to me, but when I trap for the Ctrl-F to execute a
buttons event handler, how can I prevent the beep from occurring? The
KeyDown event handler code is as follows:
// control-f is shortcut for find button
if (btnFind.Enabled and (ssCtrl in Shift) and
((Key = Ord('f')) or (Key = Ord('F')))) then
btnFindClick(Sender);
This code works fine, but the beep is confusing to the user.
Thanks for all the help.
Mike
> That makes sense to me, but when I trap for the Ctrl-F to execute a
> buttons event handler, how can I prevent the beep from occurring? The
> KeyDown event handler code is as follows:
>
> // control-f is shortcut for find button
> if (btnFind.Enabled and (ssCtrl in Shift) and
> ((Key = Ord('f')) or (Key = Ord('F')))) then
> btnFindClick(Sender);
>
> This code works fine, but the beep is confusing to the user.
>
> Thanks for all the help.
I think you're making it too hard on yourself. How is the user
supposed to know to press Ctrl+F anyhow? The normal way to do this is
to use a menu (either a main menu or popup menu) with a Ctrl+F
shortcut. When you do that the sound goes away anyhow and you don't
have to write code like the above ...
--
-Mike (TeamB)
The form is a modal form, and the reason for this is that it what the
user requested. So how can I prevent the beep?
Thanks
Mike
> The form is a modal form, and the reason for this is that it what the
> user requested. So how can I prevent the beep?
Like I said, add popup menus with the appropriate shortcuts. It's
*supposed* to beep for any other key.
--
-Mike (TeamB)
Thanks! I get it now. I hadn't thought of using a popup menu for
the form with AutoPopup set to False. That is the right way to do it.
Mike