Is this the way to check for Esc

  • Thread starter Thread starter Just Me
  • Start date Start date
J

Just Me

When I need to cancel when Esc is pressed this is what I do:

In KeyUp I set a module level variable if Esc is pressed.

Where I want to check for cancel I do a DoEvents and then check that
variable.

This is probably a long loop so DoEvents is executed often and I takes a
performance hit.



Is there a better way?

Thanks
 
When I need to cancel when Esc is pressed this is what I do:

In KeyUp I set a module level variable if Esc is pressed.

Where I want to check for cancel I do a DoEvents and then check that
variable.

This is probably a long loop so DoEvents is executed often and I takes a
performance hit.



Is there a better way?

You could execute the long-running process on a secondary thread and let the
main (UI) thread process user input as normal. That's about all I can think
of to avoid DoEvents.
 
Thanks, I've done something like that.
Bumped a counter and did DoEvents and rest the counter when it reached some
value

Thanks


Jonathan Allen said:
Avoiding DoEvents is a good thing. But if you don't wnat to deal with
threads, you can limit how often it is called.
 
I'm going to keep that in mind. I haven't yet used secondary threads but
maybe I should be thinking that way.

Thanks
 
One other thing I forgot to ask:

The code is on a UserControl which contains many controls.

Do I have to code each KeyUp or can I some how get the UserControl's KeyUp
event to catch them all?

I know I can make one method handle all the events, but is that necessary?

Guess I'm looking for a KeyPreview for a UserControl.


Thanks
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top