how to prevent F10 acting like ALT

Hi,
my problem is that I'm using the keys F1 trough F12
with the onkeydown event.
They all works like I want except F10 that works like
ALT and that I can intercept in any event.

How can I do my friends ?

I tried something like
onMessage:
if msg.msg = WM_keydown then

end;

but it seems to me that some handler is getting it's
hand first on that message
I found that F10 generates a wm_syscommand event but
I canno handle it properly : I don't want the focus to
get to the menu, I want F10 to do what I tell him to do.

Thanks n advance for your hints.

Jeurk
LVL 4
jeurkAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

ZifNabCommented:
What's your method at the moment? (where, how do you detect F1..F12)
0
jeurkAuthor Commented:
onkeydown:

if key=vk_F1 then
begin

end;
0
ZifNabCommented:
Hi jeurk,

Try this :

 if HiWord(GetKeyState(VK_F1)) <> 0 then
   begin
    { F1 pressed }
   end
  else if HiWord(GetKeyState(VK_F2))<> 0 then
   begin
   end
    else ....

Have fun!
0
Microsoft Azure 2017

Azure has a changed a lot since it was originally introduce by adding new services and features. Do you know everything you need to about Azure? This course will teach you about the Azure App Service, monitoring and application insights, DevOps, and Team Services.

ZifNabCommented:
And? What happens now?

To Check if Alt key is down you can offcourse use

      if HiWord(GetKeyState(VK_MENU)) <> 0
0
JimBob091197Commented:
In the OnKeyDown event of the form, check if F10 is pressed and set Key = 0.

E.g. From
procedure TForm1.FormKeyDown(Sender: TObject; var Key: Word; Shift: TShiftState);
begin
  if (Shift = []) and (Key = VK_F10) then
    begin
      DoSomething;
      Key := 0;
    end;
end;

JB
0
jeurkAuthor Commented:
Hello guys,
In one line:
the F10 keys do NOT generate a onKeyDown event.
Do you agree with me ?

Jeurk
0
JimBob091197Commented:
No.  The code I gave works in Delphi 3 & Win 95.  What about setting the form's KeyPreview to True?
0
ZifNabCommented:
The code I gave works in D2 on WinNT, i'm sure it must also work in Win95 and in D3. And I've put it in the OnKeyDown (of an edit).
And like JimBob says. You can use KeyPreview and check it in your main menu in the OnKeyDown.
0
jeurkAuthor Commented:
Hello again,

My form keypreview is set to true,
and in the form onkeypress,

procedure TForm1.FormKeyDown(Sender: TObject; var Key: Word; Shift: TShiftState);
begin
     //make a breakpoint on the next line
 --> if (Shift = []) and (Key = VK_F10) then
     begin
          DoSomething;
          Key := 0;
     end;
end;

----------
I run the program under windows 95 osr2 and delphi 3
If I press F10, the program doesn't stop at the breakpoint.
I promisse.
If you still don't agree let me do some more testing.
I try your code at lunch time (in half an hour ;) )
I let you know.
Anyway, thanks for trying to help me.
Jeurk.
0
JimBob091197Commented:
It's possible that the control with the focus on your form is capturing the F10 key so the form doesn't get it???
0
ZifNabCommented:
Doesn't this works ?

 if HiWord(GetKeyState(VK_F10))<> 0 then
  begin
  // Breakpoint
   DoSomething;
   Key :=0;
  end;
0
jeurkAuthor Commented:
Hi again,
I have tested things again, and it worked, the trick is to set
key to zero, and so Jimbob answered that again, if you answer
that question I will graduate you.
Sorry zifNab, but thanks to you anyway. I thinks what you
say wrks but you don't need getkeystate cause onkeydown gives
the key for you.

Ok, so my problem is solved but I still want to know following:
make a form
add a dummy menu with wahat you want in it
set keypreview
add a component that grabs messages like appEvent in the RX
library, and in the onMessage procedure type the
following code:
if msg.message = WM_keydown then
      showmessage('machin');

and you will see that you can press the key you want it will work
but not if you press F10, is it the menu that grabs the message ?
how does it do it ?

Voila!

Thanks again.
0
jeurkAuthor Commented:
again = first ;)
in one line
jimbob answered the question, or at least solved the
problem first.
0
JimBob091197Commented:
My original answer was to set Key := 0; in the OnKeyDown event.

Regarding your question about RX's AppEvents unit, I had a look but couldn't find anything they were doing to trap the F10 key.  So I tried the following, with no RX stuff, just plain old Delphi:

procedure TForm1.FormCreate(Sender: TObject);
begin
  Application.OnMessage := DoMessage;
end;

procedure TForm1.DoMessage(var Msg: TMsg; var Handled: Boolean);
begin
  if (Msg.message = WM_KEYDOWN) then
    ShowMessage('Key down');
end;

If you try this on a new project you will see that F10 doesn't trigger the ShowMessage, so it's not RX that is stopping it.  It is something built into Delphi or Windows.

I then had a look in Delphi's Forms unit at TApplication.ProcessMessage.  This is the routine that calls the TApplication's OnMessage event (in my example above).  This routine does a PeekMessage, and I suspect that the PeekMessage isn't returning the F10 (maybe because F10 is a standard Windows key for activating a menu).

JB
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
jeurkAuthor Commented:
Adjusted points to 105
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Delphi

From novice to tech pro — start learning today.