-->

OnKeydown for “-” does not get fired in Delphi 7 a

2020-05-06 14:08发布

问题:

We are using Delphi 7 enterprise edition, application is build on windows XP, testing on both Windows XP and Windows 7.

In an application we maintain, something strange is happening. For some reason hitting the "-" key (qwerty layout, between "0" and "=" keys on top) does not register at all.

We checked in the OnKeyDown of the edit we found it with, the OnKeyDown of the form (with and without key preview) and even the ProcessMessage routine, but the event for this key never reaches the application. We get the same results for OnKeyPress.

Yes, the "-" key on the numpad DOES work. Also, this behavior is only seen in this application, but if we create a new application with only the OnKeyDown of the default form in unit1.pas implemented. it does work.

So somehow we managed to tell the application to properly ignore this one key. Does anyone have an idea how this could be (un)done?

回答1:

David's comment is on the right track; You can (with version control) strip back the app until you understand what is going on. However I think that you need to understand the following concepts as well:

  1. OnKeyDown event in a form is not the only place that keyboard shortcuts could go. You should find out where else it's going to, which is why Sertac's comment is there.

  2. It is possible that something OUTSIDE your application is trapping that keyboard key (although this is more common with Control or Alt + Key combinations).

  3. It is possible that something inside your form, or elsewhere in your application is grabbing that key and consuming it.

  4. There is a good article here about KeyPreview, you need to understand that too.