Solved

how to prevent F10 acting like ALT

Posted on 1997-12-15
15
670 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
  • 6
  • 5
  • 4
15 Comments
 
LVL 8

Expert Comment

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

Author Comment

by:jeurk
Comment Utility
onkeydown:

if key=vk_F1 then
begin

end;
0
 
LVL 8

Expert Comment

by:ZifNab
Comment Utility
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
 
LVL 8

Expert Comment

by:ZifNab
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
No.  The code I gave works in Delphi 3 & Win 95.  What about setting the form's KeyPreview to True?
0
What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

 
LVL 8

Expert Comment

by:ZifNab
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
Doesn't this works ?

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

Author Comment

by:jeurk
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
Adjusted points to 105
0

Featured Post

Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

Join & Write a Comment

This article explains how to create forms/units independent of other forms/units object names in a delphi project. Have you ever created a form for user input in a Delphi project and then had the need to have that same form in a other Delphi proj…
In my programming career I have only very rarely run into situations where operator overloading would be of any use in my work.  Normally those situations involved math with either overly large numbers (hundreds of thousands of digits or accuracy re…
Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the file…
This video shows how to remove a single email address from the Outlook 2010 Auto Suggestion memory. NOTE: For Outlook 2016 and 2013 perform the exact same steps. Open a new email: Click the New email button in Outlook. Start typing the address: …

771 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

11 Experts available now in Live!

Get 1:1 Help Now