Question : Detect ESC key press in VSTO

Greetings,

I'm developing an Excel add-in in VSTO and I'm unable to solve the problem of detecting if the user has hit the ESCAPE key.  Here are the details:

The application allows a user to key bulk data into a spreadsheet for various columns.  The user then clicks an "UPDATE" button on the custom VSTO ribbon.  The application then reads each row of the spreadsheet data and passes this information to a backend system, all the while updating the spreadsheet row with a "SUCCESS" or "ERROR" status.  

The problem I have is that I would like to give the user the ability to break out of this processing loop by hitting the ESCAPE key.  But for the life of me I can't figure this out.

In VBA, a simple DoEvents within the loop would allow the loop to be terminated when the user hit the ESCAPE key.  No such luck in VSTO as the process just keeps chugging along until it's done, regardless of any keyboard keys being pressed.

Any advice or suggestions would be greatly appreciated.

Regards,
Rob

Answer : Detect ESC key press in VSTO

Barsham,

Prior to seeing your suggestion, I ended up basically doing just that.  I created a Windows popup form that had a button the user could click if they wished to stop processing.  This was the only way that I could interrupt the Excel process.  

So, once the user hits the "UPDATE" button on the ribbon bar, I display this popup form.  If processing completes unimpeded, the form will automatically close.  However, if the user hits the "STOP PROCESSING" button on this popup form, I am able to capture and change a global flag that is checked within the main update process loop.

Rob
Random Solutions  
 
programming4us programming4us