?
Solved

OnKeyDown in Delphi 5 and 6 Pro isn't working on my system

Posted on 2001-07-21
6
Medium Priority
?
437 Views
Last Modified: 2010-04-04
I created a form. Set its style to fsMDIForm.
I set the keypreview property to true;

I placed a Statusbar on the form with 6 panels (CAP, Capstatus, NumbLock, NumbLockStatus, Insert, InsStatus)

I placed a ActionList on the form and created a custom action item (Action1). This item will check the status of the keyboard and will change the CapStatus, NumbLockStatus, and InsStatus to either on or off.

When the form is created Action1 is executed and everything works as it should.

But...When I press on the Keyboard key Caps Lock....nothing happens. The OnKeyDown event is Action1.Execute;

I have also tried this code in the OnKeyDown Event just to see if any code will work:

procedure TMainForm.FormKeyDown(Sender: TObject; var Key: Word;
  Shift: TShiftState);
begin
  if (shift = ([ssalt])) then showMessage('This Works');
end;

Still...Nothing.

Any ideas?

BTW - If I put a timer component on the form and have it fire Action1.Execute (every 1000 ms) it picks up the change to the keyboard state when I change it.




I have tried this in both D5 and D6.
0
Comment
Question by:gemarti
[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
  • 3
  • 2
6 Comments
 

Accepted Solution

by:
felonious earned 150 total points
ID: 6304893
I think the problem is that you set your form as fsMDIForm.  I am currently also working on an MDI project and when I tried the mouse down even it didn't even trigger for just the MainForm.  Now if i go and open a MDIChild everything works great.  I know this doesn't help you, but it seems to be the standard behaviour of fsMDIForms.  I'll see if I can figure out a work around, but it seems to me that a nasty work around is that you could use the above code (and it would work when there is at least one MDIChild open) and also put in a timer to check for changes.
0
 
LVL 3

Expert Comment

by:nnbbb09
ID: 6304901

I think is has something to do with it being an MDI app. If the focused control is in the MDI parent then the OnKeyDown event for the MDI child won't fire. Try setting focus to a control in the MDI form and then testing it.
Let me know what happens.

Jo
0
 
LVL 3

Expert Comment

by:nnbbb09
ID: 6304932

I think is has something to do with it being an MDI app. If the focused control is in the MDI parent then the OnKeyDown event for the MDI child won't fire. Try setting focus to a control in the MDI form and then testing it.
Let me know what happens.

Jo
0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
LVL 3

Expert Comment

by:nnbbb09
ID: 6304953

Sorry about the double post. I've also re-read your question and realised that the problem is the other way around to what I had originally thought. ie : The MDI Parent has the OnKeyDown event but the MDIChild has focus.
One possible workaround (not elegant but it works) is to declare a class of TCustomForm in your MDI child. You can then typecast Application.MainForm to this class and gain access to the protected methods, one of which is KeyDown.
eg :

type
  TRedeclareForm = class(TCustomForm);

procedure TForm2.FormKeyDown(Sender: TObject; var Key: Word;
  Shift: TShiftState);
begin
  TRedeclareForm(Application.MainForm).KeyDown(Key,Shift);
end;

Jo
0
 
LVL 21

Author Comment

by:gemarti
ID: 6304955
I'm going to accept both your answer and nbbb09's answer.

I created a child form.
I put a command in the Mainform.OnCreate to set focus on the StatusBar1.
I put a command in the OnMouseMove event to trigger Action1 and the status bar started working .

Thanks for both of your help.

0
 

Expert Comment

by:felonious
ID: 6304970
Thanks, gemarti, good luck!

-felonious
0

Featured Post

Independent Software Vendors: 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!

Question has a verified solution.

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

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…
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…
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …
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
Course of the Month9 days, 11 hours left to enroll

762 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