Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

F1 key is giving me problems

Posted on 1999-06-24
12
Medium Priority
?
278 Views
Last Modified: 2010-04-06
In a program I use a lot of "hot-keys/short-cuts". Among them are F1, shift+F1, alt+F1, Ctrl+F1 and Shift+Ctrl+F1. The problem is that when used, they call the function i specify all right , but also the "help" function (winHelp). How do i take control over that process ? (sometimes i want the help to open and sometimes not).

take care  
hatecapletters
0
Comment
Question by:hatecapletters
[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
  • 3
  • 2
  • +1
12 Comments
 
LVL 17

Expert Comment

by:inthe
ID: 1384377
hi,
you could try setting the forms keyprieview to true in the object inspector or if that dont work you can disable the systems shortcut keys like so:

procedure TForm1.FormCreate(Sender: TObject);
 Var
  keys : longint;
 begin
  systemparametersinfo(97,word(true),@keys,0);
end;


procedure TForm1.FormDestroy(Sender: TObject);
 Var
  keys : longint;  
 begin
  systemparametersinfo(97,word(false),@keys,0);
end;

and when you want winhelp to appear use shellexecute to call the help file on a keyup event like so:

if Key = VK_F1 then
ShellExecute(Form.Handle,'open',pchar('notepad.exe'),nil,nil,SW_SHOWNORMAL);

Regards Barry
0
 
LVL 12

Expert Comment

by:rwilson032697
ID: 1384378
How about using the OnShortCut event? There is also an OnHelp(sp?) event in the TApplication class where you could filter them out...

Cheers,

Raymond.

0
 
LVL 1

Expert Comment

by:BlackDeath
ID: 1384379
as ray proposed -
if u're using d4 (onshortcut event's not in d3's tform).
this function provides u with the parameter handled u can set 2 true so it won't b passed on after u treating the message.
2 test the keys within this func, u test msg.charcode and use e.g. (getkeystate(vk_shift) and $80 = $80) or (getkeystate(vk_control) and $80 = $80) in order 2 check if simultaneously shift or control is pressed.

regards,

BlackDeath.
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 17

Expert Comment

by:inthe
ID: 1384380
yes i think if you have d4 then raymonds solution would be better for you.the onshortcut seems to be  more superior than keydown/up[ events as it has the handled property.
i just need to learn how to use it now :-)
0
 

Author Comment

by:hatecapletters
ID: 1384381
thank you for your comments. i'm very busy right now and havent got the time needed to try the different stuff out. the program is written in dp3 and will have to stay that way, so i cant used the onShortCut event handler.. i'll let u know as soon as i get some time to play around with it

hatecapletters
0
 
LVL 1

Expert Comment

by:BlackDeath
ID: 1384382
hatecapletters - hm.

i can't resist remarking hatecapletters ain't so much as an alias than rather a property of most experts around, right?

;-)))

BlackDeath.

oops - obviously i'm more or less a hatenearlyallcapletters...

uhm - btw:
mayb u can use

Application.OnMessage := AppMessage;

& declare a method

procedure TForm1.AppMessage(var Msg: TMsg; var Handled: Boolean);

in which u treat the msg if it's a twmkey & set handled 2 true in order 2 dump it.

i didn't try this yet, but mayb it worx...

bye,

BlackDeath.
0
 
LVL 1

Expert Comment

by:BlackDeath
ID: 1384383
now - i've tested around a little bit & this is what i came out with:

procedure TForm1.AppMessage(var Msg: TMsg; var Handled: Boolean);
begin
  if (Msg.wParam = VK_F1) and
// wParam contains the virtual key code
    (Msg.lParam and $C0 = $00) and
// lParam: bit31 - transition state: 0 - key pressed, 1 - key released
// lparam: bit30 - previous key state: 0 - key down, 1 - key up
    (Msg.message = WM_KEYDOWN) and
// only treat the wm_keydown msg !
    (GetKeyState(VK_SHIFT) and $80 = $80)
// is shift pressed simultaneously?
  then begin
      MessageDlg('Shift F1', mtInformation, [mbOk], 0);
    Handled := True;
  end
end;

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

loox a bit weird but it worx...

regards,

BlackDeath.
0
 
LVL 1

Expert Comment

by:BlackDeath
ID: 1384384
sorry, lparam bit30: 1 - key pressed, 0 - key down ...

btw:
u'll have 2 declare this procedure (AppMessage) in the private part of tform.

bye,

BlackDeath.
0
 
LVL 1

Expert Comment

by:BlackDeath
ID: 1384385
or:

  if (Msg.wParam = VK_F1) and
    (Msg.lParam and $C0 = $00) and
    (Msg.message = WM_KEYDOWN) then
   
    if (GetKeyState(VK_SHIFT) and $80 = $80) then begin
      MessageDlg('Shift F1', mtInformation, [mbOk], 0);
      Handled := True;
    end
    else if (GetKeyState(VK_CONTROL) and $80 = $80) then begin
        MessageDlg('Control F1', mtInformation, [mbOk], 0);
        Handled := True;
      end
      else if (GetKeyState(VK_MENU) and $80 = $80) then begin
          MessageDlg('Alt F1', mtInformation, [mbOk], 0);
          Handled := True;
        end
        else begin
          MessageDlg('F1', mtInformation, [mbOk], 0);
          Handled := True;
        end;

  end;

0
 

Author Comment

by:hatecapletters
ID: 1384386
sorry about the delay folks.

"inteh" thank you for you answer, but i went with "blackdeath"'s answer, and it worked just as i wanted it, no offense :-)

"Blackdeath", if you post an answer, i'll give you your hard earned points :-)

hatecapletters
0
 
LVL 17

Expert Comment

by:inthe
ID: 1384387
no trouble ,i too like blackdeaths solution :-)
0
 
LVL 1

Accepted Solution

by:
BlackDeath earned 180 total points
ID: 1384388
i'm glad it helped.

hand,

BlackDeath.
0

Featured Post

[Webinar] Lessons on Recovering from Petya

Skyport is working hard to help customers recover from recent attacks, like the Petya worm. This work has brought to light some important lessons. New malware attacks like this can take down your entire environment. Learn from others mistakes on how to prevent Petya like worms.

Question has a verified solution.

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

A lot of questions regard threads in Delphi.   One of the more specific questions is how to show progress of the thread.   Updating a progressbar from inside a thread is a mistake. A solution to this would be to send a synchronized message to the…
The uses clause is one of those things that just tends to grow and grow. Most of the time this is in the main form, as it's from this form that all others are called. If you have a big application (including many forms), the uses clause in the in…
In this video, Percona Director of Solution Engineering Jon Tobin discusses the function and features of Percona Server for MongoDB. How Percona can help Percona can help you determine if Percona Server for MongoDB is the right solution for …
How to fix incompatible JVM issue while installing Eclipse While installing Eclipse in windows, got one error like above and unable to proceed with the installation. This video describes how to successfully install Eclipse. How to solve incompa…
Suggested Courses

722 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