×
INTELLIGENT WORK FORUMS
FOR ENGINEERING PROFESSIONALS

Log In

Come Join Us!

Are you an
Engineering professional?
Join Eng-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!
  • Students Click Here

*Eng-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

Jobs

Listening keyboard events on UserForm (eg :UserForm_KeyPress)

Listening keyboard events on UserForm (eg :UserForm_KeyPress)

Listening keyboard events on UserForm (eg :UserForm_KeyPress)

(OP)
Hi ;

All is in the title.
On a macro with one UserForm, I want to catch some keyboard events.
EG : Escape key to end the macro.

I tried to use "Private Sub UserForm_KeyPress( ByVal KeyANSI As MSForms.ReturnInteger)" but unfortunatly, it doesn't work.
I copy/paste my sub on an excel macro, and it perfectly works.

I would like to avoid to listen keyboard events on each controls ...

Thanks for your tips.

SW2007 SP5
Worksatation HP wx4300 2GB
NVidia Quadro FX 3450

RE: Listening keyboard events on UserForm (eg :UserForm_KeyPress)

You may need to watch for event on all controls.  It is the control that has focus that will see the keypress event.

The best way to do this is to make a function that would react to keys, then have each control keypress event simply call that function.  This is less tedious than writing full code for each control.  If you need to interrupt a loop, be sure the loop has DoEvents call within its body.

Sometimes, when testing a form, I put a temporary "Break" command button on the form.  Easier than monitoring for KeyPress events.

batHonesty may be the best policy, but insanity is a better defense.bat
http://www.EsoxRepublic.com-SolidWorks API VB programming help

RE: Listening keyboard events on UserForm (eg :UserForm_KeyPress)

(OP)
Thanks  TheTick,

That's what I've ever done, but I think it isn't clean ...

Whereas it works on Excel, I don't understand why it doesn't on SW ... !!!

Ho ! Thanks for your tip about DoEvents that I didn't know ; sure it's useful ...

SW2007 SP5
Worksatation HP wx4300 2GB
NVidia Quadro FX 3450

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Eng-Tips Forums free from inappropriate posts.
The Eng-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Eng-Tips forums is a member-only feature.

Click Here to join Eng-Tips and talk with other members!


Resources