Solved

how to prevent F10 acting like ALT

Posted on 1997-12-15
15
690 Views
Last Modified: 2010-04-04
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
0
Comment
Question by:jeurk
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 6
  • 5
  • 4
15 Comments
 
LVL 8

Expert Comment

by:ZifNab
ID: 1353719
What's your method at the moment? (where, how do you detect F1..F12)
0
 
LVL 4

Author Comment

by:jeurk
ID: 1353720
onkeydown:

if key=vk_F1 then
begin

end;
0
 
LVL 8

Expert Comment

by:ZifNab
ID: 1353721
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
Technology Partners: 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!

 
LVL 8

Expert Comment

by:ZifNab
ID: 1353722
And? What happens now?

To Check if Alt key is down you can offcourse use

      if HiWord(GetKeyState(VK_MENU)) <> 0
0
 
LVL 5

Expert Comment

by:JimBob091197
ID: 1353723
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
 
LVL 4

Author Comment

by:jeurk
ID: 1353724
Hello guys,
In one line:
the F10 keys do NOT generate a onKeyDown event.
Do you agree with me ?

Jeurk
0
 
LVL 5

Expert Comment

by:JimBob091197
ID: 1353725
No.  The code I gave works in Delphi 3 & Win 95.  What about setting the form's KeyPreview to True?
0
 
LVL 8

Expert Comment

by:ZifNab
ID: 1353726
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
 
LVL 4

Author Comment

by:jeurk
ID: 1353727
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
 
LVL 5

Expert Comment

by:JimBob091197
ID: 1353728
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
 
LVL 8

Expert Comment

by:ZifNab
ID: 1353729
Doesn't this works ?

 if HiWord(GetKeyState(VK_F10))<> 0 then
  begin
  // Breakpoint
   DoSomething;
   Key :=0;
  end;
0
 
LVL 4

Author Comment

by:jeurk
ID: 1353730
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
 
LVL 4

Author Comment

by:jeurk
ID: 1353731
again = first ;)
in one line
jimbob answered the question, or at least solved the
problem first.
0
 
LVL 5

Accepted Solution

by:
JimBob091197 earned 100 total points
ID: 1353732
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
 
LVL 4

Author Comment

by:jeurk
ID: 1353733
Adjusted points to 105
0

Featured Post

[Webinar] Learn How Hackers Steal Your Credentials

Do You Know How Hackers Steal Your Credentials? Join us and Skyport Systems to learn how hackers steal your credentials and why Active Directory must be secure to stop them. Thursday, July 13, 2017 10:00 A.M. PDT

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In this tutorial I will show you how to use the Windows Speech API in Delphi. I will only cover basic functions such as text to speech and controlling the speed of the speech. SAPI Installation First you need to install the SAPI type library, th…
Introduction Raise your hands if you were as upset with FireMonkey as I was when I discovered that there was no TListview.  I use TListView in almost all of my applications I've written, and I was not going to compromise by resorting to TStringGrid…
There's a multitude of different network monitoring solutions out there, and you're probably wondering what makes NetCrunch so special. It's completely agentless, but does let you create an agent, if you desire. It offers powerful scalability …
In this video we outline the Physical Segments view of NetCrunch network monitor. By following this brief how-to video, you will be able to learn how NetCrunch visualizes your network, how granular is the information collected, as well as where to f…

695 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