• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 281
  • Last Modified:

F1 key is giving me problems

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
hatecapletters
Asked:
hatecapletters
  • 6
  • 3
  • 2
  • +1
1 Solution
 
intheCommented:
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
 
rwilson032697Commented:
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
 
BlackDeathCommented:
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
2018 Annual Membership Survey

Here at Experts Exchange, we strive to give members the best experience. Help us improve the site by taking this survey today! (Bonus: Be entered to win a great tech prize for participating!)

 
intheCommented:
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
 
hatecaplettersAuthor Commented:
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
 
BlackDeathCommented:
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
 
BlackDeathCommented:
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
 
BlackDeathCommented:
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
 
BlackDeathCommented:
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
 
hatecaplettersAuthor Commented:
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
 
intheCommented:
no trouble ,i too like blackdeaths solution :-)
0
 
BlackDeathCommented:
i'm glad it helped.

hand,

BlackDeath.
0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

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

  • 6
  • 3
  • 2
  • +1
Tackle projects and never again get stuck behind a technical roadblock.
Join Now