I have a vb.net Autocad add-in which runs an iterative routine with a while..wend loop that often takes a few minutes to finish.
The routine is very stable and always restores user control eventually, but if the user hits the escape key while it is running, a fatal error occurs in acad.exe.
Does anyone know if there is a way to detect that the escape key has been pressed so the routine is exited?
Solved! Go to Solution.
//before your while loop
//do your work
const int KEYDOWN= 0x0100;
void myEscWatcher(object sender, PreTranslateMessageEventArgs messageDetails)
if (messageDetails.Message.message == KEYDOWN && ((Keys)(int)messageDetails.Message.wParam & Keys.KeyCode) == Keys.Escape)
//do something when ESCAPE has been pressed, for example
AutoCAD has a property to determine whenever the ESCAPE was pressed, check the posts below:
Easy as that!
Just for convenience, below is the relevant piece of code from the first link above in VB. I had to place it in a few different places to catch the keypress reliably, but it works well if in the right spot.
If HostApplicationServices.Current.UserBreak = True Then
Throw New Autodesk.AutoCAD.Runtime.Exception(ErrorStatus.Use
Start with some of our most frequented solutions to get help installing your software.