问题
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:
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.
It is possible that something OUTSIDE your application is trapping that keyboard key (although this is more common with Control or Alt + Key combinations).
It is possible that something inside your form, or elsewhere in your application is grabbing that key and consuming it.
There is a good article here about KeyPreview, you need to understand that too.
来源:https://stackoverflow.com/questions/10449271/onkeydown-for-does-not-get-fired-in-delphi-7-application