OnKeyDown() Event Failure
John K.
Bacau,

Jul 8, 2011
55 Posts

OnKeyDown() event failure

Hi there! I'm developing an application in which a form that's loaded has to respond to some key pressed from the keyboard. When the form is loaded, the OnKeyDown() event works fine, but if I minimize the form or I just press Alt+TAB (to focus on another opened application), when I return to the loaded form, the OnKeyDown() event is not working any more! Why? I have to close the form and reload it in order to make this event functionable. It's frustrating or so... Can I fix this up? Or, how can I make the loaded form "always on top", so the user couldn't minimize it (just closing it) ? Please, help me up!

Victor B.
Lake Forest, CA

Jul 8, 2011
91 Posts

Re: OnKeyDown() event failure

Hi Alex,

I set up a simple example where the OnKeyDown() event updates a counter.  Alt+Tab did not disable the OnKeyDown() event.  I have attached the example program that I created.  Check to see if it works on your system.

To answer your second question, you can disable the minimum and maximum controls by right-clicking on your form in the form editor and opening the Properties window.  If you click on the Window page in the Properties Editor, you will see checkboxes to enable/disable MinButton and MaxButton.  Alternatively, you can also change the BorderStyle from the default 'Sizable' to 'Fixed Dialog' which will have a similar effect.

Regards,
Victor Brode


File Attachment:
OnKeyDownTest.rar

John K.
Bacau,

Jul 9, 2011
55 Posts

Re: OnKeyDown() event failure

Hi, Victor! Thank you for your reply! Your program works indeed. But mine still doesn't :(. If I load the form, it works, but if I click on another application loaded in the taskbar, after that I return to my opened form  the OnKeyDown event is not working anymore. I think there's a problem with my variables and procedures. Now I've moved the used variables in the variables section of the form, but when I try to move the used procedures, I can't! I don't know why I can't create a procedure within my form. It has the Procedure section (near Variables, cht1, btn1 - the controls within my form), but when I double click it, it opens and just it. No right-click options (no "Insert procedure at" or so...) ! Why? Is there a special way to create procedures within a form?

John K.
Bacau,

Jul 11, 2011
55 Posts

Re: OnKeyDown() event failure

I've found the problem source: there's a button on my form and when I reactivate the form, this button automatically receives focus, so the form's OnKeyDown event isn't working anymore... How can I cancel the option where a button receives focus on reactivating the window? I've tried with Form.SetFocus() on OnActivate() event, but no use! :(
Victor, try to add a button to your test form, and you will see that the counter will stop working if you use Alt+TAB and after that reactivate the form... I just don't know how to disable this feature: setting a sort of auto-focus on the button within the form! :(

Solution Available
Victor B.
Lake Forest, CA

Jul 11, 2011
91 Posts

Re: OnKeyDown() event failure

Hi Alex,

You can set the Form's KeyPreview property to True.  This will cause the Form to receive keystrokes generated from any of it's child controls before they are handled by the control.  Set this in the Form Properties editor in the Window tab.

To create a new procedure within your form, click on the Procedure entry and select 'Insert Procedure After...' from the Insert Menu.  Or use the shortcut keystroke Shift+Alt+Insert.

Regards,
Victor Brode

John K.
Bacau,

Jul 11, 2011
55 Posts

Re: OnKeyDown() event failure

Thank you very much for you help, Victor! Your reply helped me a lot!! Have a nice day!

Best regards,

Alex J.



Please Note
You need to have a M@GIC account to participate in the Forums.
Not yet registered on our website? Click here to register today!

All content, information and opinions presented on the Marvin Test Solutions User Forums are those of the authors of the posts and messages and not Marvin Test Solutions'. All attachments and files are downloaded at your own risk. [Read More]