<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: Capturing keystroke to cancel during commandmanager.pick operation in Inventor Programming Forum</title>
    <link>https://forums.autodesk.com/t5/inventor-programming-forum/capturing-keystroke-to-cancel-during-commandmanager-pick/m-p/8290954#M84027</link>
    <description>&lt;P&gt;This is indeed a VB add-in.&amp;nbsp; Not iLogic.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I've come across a few solutions using a cancel button, but unless I can tie that to keyboard input, I don't know that I care for it as being better than default performance.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I just figure that a users natural instincts, when done selecting points, is to hit one of the typical "I'M DONE!" or "STOP" or "CANCEL" keys, to end or move past that particular step of the process, and wanted to have my add-in react to that input intuitively.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I'm obviously not having much luck.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I wouldn't mind seeing what you have for the cancel, though.&amp;nbsp; I may have misunderstood, initially, and it may do what I want, or similar to it.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks for the quick response!&lt;/P&gt;</description>
    <pubDate>Tue, 25 Sep 2018 13:28:46 GMT</pubDate>
    <dc:creator>josh.nieman</dc:creator>
    <dc:date>2018-09-25T13:28:46Z</dc:date>
    <item>
      <title>Capturing keystroke to cancel during commandmanager.pick operation</title>
      <link>https://forums.autodesk.com/t5/inventor-programming-forum/capturing-keystroke-to-cancel-during-commandmanager-pick/m-p/8290797#M84025</link>
      <description>&lt;P&gt;I am having exceptions thrown that I can't figure out the problem of.&lt;/P&gt;&lt;P&gt;From a form, a user clicks a button to begin a sub that adds model annotation leaders one at a time.&lt;/P&gt;&lt;P&gt;It loops until a certain boolean is set True.&lt;/P&gt;&lt;P&gt;The boolean is set to True when another sub, running on a timer-tick, detects any of a few keys are pressed.&amp;nbsp; The sub to add the leaders is perfectly fine and works without error, when not being looped as I am trying to do.&lt;/P&gt;&lt;P&gt;When I press "esc" though, I get this error:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;+ $exception {"The parameter is incorrect. (Exception from HRESULT: 0x80070057 (E_INVALIDARG))"} System.ArgumentException&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Here's what I have:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Calling the sub:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;BR /&gt;Private Sub button_Click(sender As Object, e As EventArgs) Handles button.Click&lt;BR /&gt;&lt;BR /&gt;While Trip = False 'Do the thing until the user doesn't want to do the thing anymore&lt;BR /&gt;AddLeader()&lt;BR /&gt;End While&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Here's the while loop:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;Private Declare Function GetAsyncKeyState Lib "user32" (ByVal vkey As Integer) As Short

'Timer 'enable' and 'interval' are set in the form code where the form is instantiated
Private Sub Timer1_tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
Dim KeySpace As Boolean
Dim KeyEnter As Boolean
Dim KeyEsc As Boolean
Dim KeyCancel As Boolean
KeySpace = GetAsyncKeyState(Keys.Space)
KeyEnter = GetAsyncKeyState(Keys.Enter)
KeyEsc = GetAsyncKeyState(Keys.Escape)
KeyCancel = GetAsyncKeyState(Keys.Cancel)

If KeySpace Or KeyEnter Or KeyEsc Or KeyCancel = True Then
Trip = True
Else
Trip = False
End If
End Sub&lt;BR /&gt;&lt;BR /&gt;&lt;/PRE&gt;&lt;P&gt;Additionally, nothing happens when I hit spacebar or enter.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Can anyone spot my mistake and give me some pointers, please?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 25 Sep 2018 12:39:28 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/inventor-programming-forum/capturing-keystroke-to-cancel-during-commandmanager-pick/m-p/8290797#M84025</guid>
      <dc:creator>josh.nieman</dc:creator>
      <dc:date>2018-09-25T12:39:28Z</dc:date>
    </item>
    <item>
      <title>Re: Capturing keystroke to cancel during commandmanager.pick operation</title>
      <link>https://forums.autodesk.com/t5/inventor-programming-forum/capturing-keystroke-to-cancel-during-commandmanager-pick/m-p/8290849#M84026</link>
      <description>&lt;P&gt;My first question is if you're trying to achieve this through iLogic or through an Add-In?&amp;nbsp; iLogic doesn't support WithEvents tracking through keyboard or mouse like a typical VB rule.&amp;nbsp; The best workaround I've found is by making an External Rule to go with a Global Form that has a Cancel button in it, it's not the best or most stable workaround, but I can provide that if you want to try it.&amp;nbsp; Other than that, if you're just looking for a way to escape an infinite loop, before the loop starts put in an On Error Goto then you can use that error to your advantage to get out of the loop.&lt;/P&gt;</description>
      <pubDate>Tue, 25 Sep 2018 12:57:56 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/inventor-programming-forum/capturing-keystroke-to-cancel-during-commandmanager-pick/m-p/8290849#M84026</guid>
      <dc:creator>philip1009</dc:creator>
      <dc:date>2018-09-25T12:57:56Z</dc:date>
    </item>
    <item>
      <title>Re: Capturing keystroke to cancel during commandmanager.pick operation</title>
      <link>https://forums.autodesk.com/t5/inventor-programming-forum/capturing-keystroke-to-cancel-during-commandmanager-pick/m-p/8290954#M84027</link>
      <description>&lt;P&gt;This is indeed a VB add-in.&amp;nbsp; Not iLogic.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I've come across a few solutions using a cancel button, but unless I can tie that to keyboard input, I don't know that I care for it as being better than default performance.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I just figure that a users natural instincts, when done selecting points, is to hit one of the typical "I'M DONE!" or "STOP" or "CANCEL" keys, to end or move past that particular step of the process, and wanted to have my add-in react to that input intuitively.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I'm obviously not having much luck.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I wouldn't mind seeing what you have for the cancel, though.&amp;nbsp; I may have misunderstood, initially, and it may do what I want, or similar to it.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks for the quick response!&lt;/P&gt;</description>
      <pubDate>Tue, 25 Sep 2018 13:28:46 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/inventor-programming-forum/capturing-keystroke-to-cancel-during-commandmanager-pick/m-p/8290954#M84027</guid>
      <dc:creator>josh.nieman</dc:creator>
      <dc:date>2018-09-25T13:28:46Z</dc:date>
    </item>
    <item>
      <title>Re: Capturing keystroke to cancel during commandmanager.pick operation</title>
      <link>https://forums.autodesk.com/t5/inventor-programming-forum/capturing-keystroke-to-cancel-during-commandmanager-pick/m-p/8291088#M84028</link>
      <description>&lt;P&gt;For Inventor Add-Ins, mouse and keyboard interaction can be achieved through the CommandManager.CreateInteractionEvents As InteractionEvents, then keyboard/mouse and other Events can be tracked with a bunch of subs.&amp;nbsp; However I rarely code Add-Ins so I'm not a good reference for that.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;For the Cancel button I use this External Rule called Cancel:&lt;/P&gt;&lt;P&gt;SyntaxEditor Code Snippet&lt;/P&gt;&lt;PRE&gt;&lt;SPAN&gt;Public&lt;/SPAN&gt; &lt;SPAN&gt;Class&lt;/SPAN&gt; &lt;SPAN&gt;CancelButton&lt;/SPAN&gt;
	&lt;SPAN&gt;Dim&lt;/SPAN&gt; &lt;SPAN&gt;Cancel&lt;/SPAN&gt; &lt;SPAN&gt;As&lt;/SPAN&gt; &lt;SPAN&gt;Boolean&lt;/SPAN&gt; = &lt;SPAN&gt;False&lt;/SPAN&gt;
	&lt;SPAN&gt;Sub&lt;/SPAN&gt; &lt;SPAN&gt;Main&lt;/SPAN&gt;
		&lt;SPAN&gt;SharedVariable&lt;/SPAN&gt;(&lt;SPAN&gt;"Cancel"&lt;/SPAN&gt;) = &lt;SPAN&gt;True&lt;/SPAN&gt;
	&lt;SPAN&gt;End&lt;/SPAN&gt; &lt;SPAN&gt;Sub&lt;/SPAN&gt;
&lt;SPAN&gt;End&lt;/SPAN&gt; &lt;SPAN&gt;Class&lt;/SPAN&gt;&lt;/PRE&gt;&lt;P&gt;Make a form in Global Forms called Cancel, just drag the Cancel rule from the dialog on the left of the Form Editor to make a button, then save the form and close editor.&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Cancel_edited.jpg" style="width: 400px;"&gt;&lt;img src="https://forums.autodesk.com/t5/image/serverpage/image-id/550096iCCAC910CE39AD0D6/image-size/medium?v=v2&amp;amp;px=400" role="button" title="Cancel_edited.jpg" alt="Cancel_edited.jpg" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Then to use that button in any rule you first have to use these lines&amp;nbsp;toward the beginning of the rule:&lt;/P&gt;&lt;P&gt;SyntaxEditor Code Snippet&lt;/P&gt;&lt;PRE&gt;&lt;SPAN&gt;iLogicVb&lt;/SPAN&gt;.&lt;SPAN&gt;RunExternalRule&lt;/SPAN&gt;(&lt;SPAN&gt;"Cancel"&lt;/SPAN&gt;)
&lt;SPAN&gt;If&lt;/SPAN&gt; &lt;SPAN&gt;SharedVariable&lt;/SPAN&gt;(&lt;SPAN&gt;"Cancel"&lt;/SPAN&gt;) = &lt;SPAN&gt;True&lt;/SPAN&gt; &lt;SPAN&gt;Then&lt;/SPAN&gt; &lt;SPAN&gt;SharedVariable&lt;/SPAN&gt;(&lt;SPAN&gt;"Cancel"&lt;/SPAN&gt;) = &lt;SPAN&gt;False&lt;BR /&gt;&lt;/SPAN&gt;&lt;SPAN&gt;iLogicForm&lt;/SPAN&gt;.&lt;SPAN&gt;ShowGlobal&lt;/SPAN&gt;(&lt;SPAN&gt;"Cancel"&lt;/SPAN&gt;, &lt;SPAN&gt;FormMode&lt;/SPAN&gt;.&lt;SPAN&gt;NonModal&lt;/SPAN&gt;)&lt;/PRE&gt;&lt;P&gt;The first line&amp;nbsp;will run the rule so it will create the SharedVariable("Cancel") which is similar to a public variable.&amp;nbsp; Then the second line will change the variable to False.&amp;nbsp; Then the third line will make the Form with the Cancel button pop up.&amp;nbsp; Anytime the rule is run again by clicking the Cancel button in the form, the variable will change to False.&amp;nbsp; I've mainly used this for long running operations like a mass export of PDF drawings or flat pattern DXFs, I just check if the shared variable Cancel is True at the right points to exit long loops.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;EDIT: The only thing I forgot to mention is there's no way to close a form with an iLogic rule, so you have to manually close the form yourself.&lt;/P&gt;</description>
      <pubDate>Tue, 25 Sep 2018 14:18:46 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/inventor-programming-forum/capturing-keystroke-to-cancel-during-commandmanager-pick/m-p/8291088#M84028</guid>
      <dc:creator>philip1009</dc:creator>
      <dc:date>2018-09-25T14:18:46Z</dc:date>
    </item>
    <item>
      <title>Re: Capturing keystroke to cancel during commandmanager.pick operation</title>
      <link>https://forums.autodesk.com/t5/inventor-programming-forum/capturing-keystroke-to-cancel-during-commandmanager-pick/m-p/8291106#M84029</link>
      <description>&lt;P&gt;Thanks for the contribution!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;It DOES look like you are correct.&amp;nbsp; I had not come across this in the API and apparently my google-fu was weak this morning and yesterday, as I never came across this:&lt;/P&gt;&lt;P&gt;&lt;A href="https://knowledge.autodesk.com/search-result/caas/CloudHelp/cloudhelp/2018/ENU/Inventor-API/files/InteractionEventsSink-Sample-htm.html" target="_blank"&gt;https://knowledge.autodesk.com/search-result/caas/CloudHelp/cloudhelp/2018/ENU/Inventor-API/files/InteractionEventsSink-Sample-htm.html&lt;/A&gt;&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;Which APPEARS to have what I'll need to get it done.&amp;nbsp; I think I was too focused in trying to make a particular method work, and needed to broaden my search.&amp;nbsp; Thanks again!&amp;nbsp; After I finish up my current task, I'll be sure to get on this, and try to post my results when I have something working.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 25 Sep 2018 14:18:31 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/inventor-programming-forum/capturing-keystroke-to-cancel-during-commandmanager-pick/m-p/8291106#M84029</guid>
      <dc:creator>josh.nieman</dc:creator>
      <dc:date>2018-09-25T14:18:31Z</dc:date>
    </item>
    <item>
      <title>Re: Capturing keystroke to cancel during commandmanager.pick operation</title>
      <link>https://forums.autodesk.com/t5/inventor-programming-forum/capturing-keystroke-to-cancel-during-commandmanager-pick/m-p/12640968#M84030</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;I had a similar problem myself (using iLogic) and the following solution seems to work:&lt;/P&gt;&lt;LI-CODE lang="visual-basic"&gt;	Dim oSelOcc As ComponentOccurrence
	oSelOcc = ThisApplication.CommandManager.Pick(SelectionFilterEnum.kAssemblyOccurrenceFilter, "Select a component to delete")
	
	'Exit rule if nothing is selected
	If oSelOcc Is Nothing Then
		Return
	End If&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Pressing escape moves the program past the CommandManager line and the variable is subsequently nothing so program exits.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;/Fredrik&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 14 Mar 2024 16:20:39 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/inventor-programming-forum/capturing-keystroke-to-cancel-during-commandmanager-pick/m-p/12640968#M84030</guid>
      <dc:creator>fredform</dc:creator>
      <dc:date>2024-03-14T16:20:39Z</dc:date>
    </item>
    <item>
      <title>Re: Capturing keystroke to cancel during commandmanager.pick operation</title>
      <link>https://forums.autodesk.com/t5/inventor-programming-forum/capturing-keystroke-to-cancel-during-commandmanager-pick/m-p/12643608#M84031</link>
      <description>&lt;P&gt;Good sample,&amp;nbsp;&lt;a href="https://forums.autodesk.com/t5/user/viewprofilepage/user-id/9171030"&gt;@fredform&lt;/a&gt;&amp;nbsp;!&lt;BR /&gt;&lt;BR /&gt;Your method is (imo) the easiest and smoothest when using built-in Inventor UI commands such as &lt;STRONG&gt;Pick&lt;/STRONG&gt;&amp;nbsp;because it's inheriting the built-in behaviors Autodesk devs built in to that User Command by means of using the &lt;U&gt;&lt;STRONG&gt;Application.CommandManager&amp;nbsp;&lt;/STRONG&gt;&lt;/U&gt;&lt;BR /&gt;&lt;BR /&gt;Since I apparently failed to follow up, those years ago, here's what I've done since:&lt;/P&gt;&lt;P&gt;For any add-ins that are firing off custom functions/commands/subs/methods/whatever, you may find yourself having to build something like that from scratch. If that's the case, I found that using the other Interaction/Command manager objects - pertinent to this thread topic is:&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;Use the &lt;STRONG&gt;&lt;U&gt;CommandManger.InteractionEvents&lt;/U&gt;&lt;/STRONG&gt; (object)&lt;/P&gt;&lt;P&gt;---created via &lt;STRONG&gt;&lt;U&gt;Application.CommandManager.CreateInteractionEvents&lt;/U&gt;&lt;/STRONG&gt;&amp;nbsp;(method)&lt;BR /&gt;&lt;BR /&gt;It lets you start, stop the events, or even create a native &lt;U&gt;&lt;STRONG&gt;MiniToolbar&lt;/STRONG&gt; &lt;/U&gt;while the &lt;U&gt;&lt;STRONG&gt;InteractionEvents&lt;/STRONG&gt; &lt;/U&gt;is active. Part of the properties of the &lt;U&gt;&lt;STRONG&gt;InteractionEvents&lt;/STRONG&gt; &lt;/U&gt;object is &lt;STRONG&gt;&lt;U&gt;KeyboardEvents&lt;/U&gt;,&lt;/STRONG&gt;&amp;nbsp;&lt;U&gt;&lt;STRONG&gt;MouseEvents&lt;/STRONG&gt;&lt;/U&gt;, &lt;STRONG&gt;&lt;U&gt;MeasureEvents&lt;/U&gt;,&lt;/STRONG&gt;&amp;nbsp;&lt;U&gt;&lt;STRONG&gt;SelectEvents&lt;/STRONG&gt;&amp;nbsp;&lt;/U&gt;objects amongst more. &lt;U&gt;&lt;STRONG&gt;KeyboardEvents&lt;/STRONG&gt;&amp;nbsp;&lt;/U&gt;has the typical &lt;STRONG&gt;OnKeyDown&lt;/STRONG&gt;,&amp;nbsp;&lt;STRONG&gt;OnKeyPress&lt;/STRONG&gt;,&amp;nbsp;&lt;STRONG&gt;OnKeyUp&lt;/STRONG&gt; event listeners, for example.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;...and until now, I didn't know (or since forgot) that there's a &lt;STRONG&gt;ShiftStateEnum&lt;/STRONG&gt;&amp;nbsp;property attached to the &lt;STRONG&gt;KeyboardEvents&lt;/STRONG&gt; object, which returns the corresponding constant for the state of the SHIFT, CTRL, ALT keys.&amp;nbsp; Handy.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;You can wrap your command in an &lt;STRONG&gt;InteractionEvents&lt;/STRONG&gt;&amp;nbsp;object's Start/Stop and inherit all the cool stuff that comes with it, and know what a user's doing, and handle their inputs appropriately - or inappropriately if you're into that kind of evil.&lt;BR /&gt;&lt;BR /&gt;Bonus factoid: You can also use the &lt;U&gt;&lt;STRONG&gt;Application.TransactionManager&lt;/STRONG&gt;&lt;/U&gt;&amp;nbsp;object to improve tangential UX things like wrapping up a lot of steps up into a single undo entry.&lt;/P&gt;&lt;P&gt;(Example, if your code "places" 20 different components into the assembly, and you end up with 20 "Undo Place Component" in the undo button drop-down, you can wrap it up into a single &lt;U&gt;Undo My Cool Components Macro&lt;/U&gt;&amp;nbsp;entry that undoes them all in one go.)&lt;/P&gt;</description>
      <pubDate>Fri, 15 Mar 2024 16:31:48 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/inventor-programming-forum/capturing-keystroke-to-cancel-during-commandmanager-pick/m-p/12643608#M84031</guid>
      <dc:creator>josh.nieman</dc:creator>
      <dc:date>2024-03-15T16:31:48Z</dc:date>
    </item>
    <item>
      <title>Re: Capturing keystroke to cancel during commandmanager.pick operation</title>
      <link>https://forums.autodesk.com/t5/inventor-programming-forum/capturing-keystroke-to-cancel-during-commandmanager-pick/m-p/12644695#M84032</link>
      <description>&lt;P&gt;Really good information there &lt;a href="https://forums.autodesk.com/t5/user/viewprofilepage/user-id/4998597"&gt;@josh.nieman&lt;/a&gt;! Thanks for sharing!&lt;/P&gt;</description>
      <pubDate>Sat, 16 Mar 2024 09:10:02 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/inventor-programming-forum/capturing-keystroke-to-cancel-during-commandmanager-pick/m-p/12644695#M84032</guid>
      <dc:creator>fredform</dc:creator>
      <dc:date>2024-03-16T09:10:02Z</dc:date>
    </item>
  </channel>
</rss>

