Trap the Escape key from within AddIn

Trap the Escape key from within AddIn

larry.daubenspeck
Advocate Advocate
904 Views
5 Replies
Message 1 of 6

Trap the Escape key from within AddIn

larry.daubenspeck
Advocate
Advocate

Can someone please show me an event handler (or whatever is needed) for bailing out of an AddIn?  I'm using VB.net.  The end users would prefer to use the ESCAPE key for this.  Many thanks!

Larry Daubenspeck
Software Programmer
Draper, Inc.
0 Likes
905 Views
5 Replies
Replies (5)
Message 2 of 6

xiaodong_liang
Autodesk Support
Autodesk Support

Hi,

 

Not sure how is your workflow, but have your tried with KeyDown of the dialog of your add-in? something like below:

 

Private Sub MyForm_KeyDown( _
ByVal sender As System.Object, _
ByVal e As System.Windows.Forms.KeyEventArgs) _
Handles MyBase.KeyDown

 

' shortcut ESC key
If e.KeyCode = Keys.Escape Then
    'do what you need
End If

End Sub

0 Likes
Message 3 of 6

larry.daubenspeck
Advocate
Advocate

Thanks for that.  However, this particular addin doesn't use a dialog.  Once launched, it iterates through all the components, finds pulleys, creates a path, and finally sweeps a cable into existence.

Larry Daubenspeck
Software Programmer
Draper, Inc.
0 Likes
Message 4 of 6

Anonymous
Not applicable

Is your question how to let users cancel a long-running operation?

As in, you want to show a progress bar, and if the user presses escape, the operation stops?

This thread on Stack Overflow uses native interop (DllImport) to test key state:

http://stackoverflow.com/questions/3829725/winforms-retrieve-keyboard-state-without-form-usercontrol

You probably want to integrate with the built-in progress bar in Inventor though.

0 Likes
Message 5 of 6

xiaodong_liang
Autodesk Support
Autodesk Support

Hi,

 

sounds like you just want to trap the key events of Inventor? If yes, InteractionEvents.KeyboardEvents can help. API help reference has some code demos.

0 Likes
Message 6 of 6

larry.daubenspeck
Advocate
Advocate

Thanks...I'll give that a whirl sometime.

Larry Daubenspeck
Software Programmer
Draper, Inc.
0 Likes