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
Solved

how to prevent F10 acting like ALT

Posted on 1997-12-15
15
677 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
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
Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

 
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

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

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

Suggested Solutions

Introduction The parallel port is a very commonly known port, it was widely used to connect a printer to the PC, if you look at the back of your computer, for those who don't have newer computers, there will be a port with 25 pins and a small print…
Introduction I have seen many questions in this Delphi topic area where queries in threads are needed or suggested. I know bumped into a similar need. This article will address some of the concepts when dealing with a multithreaded delphi database…
Email security requires an ever evolving service that stays up to date with counter-evolving threats. The Email Laundry perform Research and Development to ensure their email security service evolves faster than cyber criminals. We apply our Threat…
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…

856 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