Link to home
Start Free TrialLog in
Avatar of tdk_man
tdk_man

asked on

Keypresses Like F1, F2 etc.

My application is MDI and each child window has a memo on it.

When you press keys, it appears in the memo as you would expect as the memo has focus. However, I still want the parent form to respond to things like the function keys and Ctrl-key combinations.

Is there a good, bad or easy way to do this?

TDK_Man
Avatar of tdk_man
tdk_man

ASKER

OK, I've more or less solved this myself. What wasn't working before now seems to have started working now!

The only thing I don't seem to be able to detect is Ctrl combinations like Ctrl-G so I can pop up a panel for a Goto line number feature.

TDK_Man
You can use Virtual Keys
make a search in delphi help about Virtual Keys & you'll find a good example.
if you didn't I'll send you an easy code.
Avatar of tdk_man

ASKER

I just came back to delete this question as I'd found what I was looking for. Virtual keys didn't really help a lot actually and I did it in the end by pinching info out of two separate code examples:

  If (key=71) and (shift = [ssCtrl])  Then
    Begin
      // Ctrl-G  Goto Line Number
    End;

Thanks anyway!

TDK_Man
Avatar of tdk_man

ASKER

Application for question to be deleted made with mods.

Suggestion made unfortunately did not solve the problem. (Virtual Keys can be used to detect the Control key but apparently not with another key such as Ctrl-G).
At risk of being ignored ;-) why don't you use the FormKeyDown (or component version of KeyDown) and send that to the parent form?

procedure TForm1.FormKeyDown(Sender: TObject; var Key: Word; Shift: TShiftState);
begin
  Form2.FormKeyDown(Sender, Key, Shift);
end;

That captures virtually every keypress with the exceptions of PrtScr and one or two others.

Geoff M.
Avatar of tdk_man

ASKER

gmayo

That's what my code (posted above) does...  :)

It uses both the shift and key values - rather than Virtual Keys.

TDK_Man
You could use keyboard event.

Example:

keybd_event(vk_return,0,0,0)

If you want to do two keys:

keybd_event(vk_control,0,0,0);
keybd_event(vk_escape,0,0,0);

Regards,
Hypoviax

TDK_Man - I've read through all your posts and I cannot find any which mention FormKeyDown...!

Geoff M.
Avatar of tdk_man

ASKER

Sorry - you misunderstood what I meant.

When I said "That's what my code (posted above) does", I was refering to the use of 'key' and 'shift' rather than Virtual Keys:

  If (key=71) and (shift = [ssCtrl])  Then
    Begin
      // Ctrl-G  Goto Line Number
    End;

... which is in my memo's KeyDown section.

TDK_Man
ASKER CERTIFIED SOLUTION
Avatar of Lunchy
Lunchy
Flag of Canada image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial