Solved

Keypresses Like F1, F2 etc.

Posted on 2003-11-18
11
572 Views
Last Modified: 2011-09-20
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
0
Comment
Question by:tdk_man
11 Comments
 
LVL 1

Author Comment

by:tdk_man
ID: 9775163
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
0
 
LVL 2

Expert Comment

by:TheLeader
ID: 9775166
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.
0
 
LVL 1

Author Comment

by:tdk_man
ID: 9775385
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
0
 
LVL 1

Author Comment

by:tdk_man
ID: 9775571
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).
0
 
LVL 8

Expert Comment

by:gmayo
ID: 9777275
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.
0
Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

 
LVL 1

Author Comment

by:tdk_man
ID: 9782999
gmayo

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

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

TDK_Man
0
 
LVL 5

Expert Comment

by:Hypoviax
ID: 9783834
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

0
 
LVL 8

Expert Comment

by:gmayo
ID: 9785832
TDK_Man - I've read through all your posts and I cannot find any which mention FormKeyDown...!

Geoff M.
0
 
LVL 1

Author Comment

by:tdk_man
ID: 9789709
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
0
 
LVL 2

Accepted Solution

by:
Lunchy earned 0 total points
ID: 9803142
PAQed, with points refunded (300)

Lunchy
Friendly Neighbourhood Community Support Admin
0

Featured Post

How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

Join & Write a Comment

Suggested Solutions

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…
Have you ever had your Delphi form/application just hanging while waiting for data to load? This is the article to read if you want to learn some things about adding threads for data loading in the background. First, I'll setup a general applica…
This video discusses moving either the default database or any database to a new volume.
This video demonstrates how to create an example email signature rule for a department in a company using CodeTwo Exchange Rules. The signature will be inserted beneath users' latest emails in conversations and will be displayed in users' Sent Items…

746 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