JigPromptStringOptions PromptStatus.Cancel on Escape

JigPromptStringOptions PromptStatus.Cancel on Escape

ama3UD9K
Explorer Explorer
558 Views
3 Replies
Message 1 of 4

JigPromptStringOptions PromptStatus.Cancel on Escape

ama3UD9K
Explorer
Explorer

Hi everyone,

 

I'm having issues with JigPromptStringOptions within a Jig.

Using the following code I'm unable to get a PromptStatus.Cancel when the user presses Escape.

Due to this I'm not able to differentiate between a Escape/Enter/Space key.

Is there anyway for me to know when a user presses the escape key here?

 

  Private Function promptRadius(prompts As JigPrompts) As SamplerStatus
    Dim retVal As SamplerStatus = SamplerStatus.NoChange

    Try
      ' Must use a string acquire so that we can get the string user input.
      ' Use the "handlespointmonitor" to save the current point.
      Dim jppo As New JigPromptStringOptions With {.AppendKeywordsToMessage = False}

      If isDiameter Then
        jppo.Message = vbLf & "Specify the diameter or "
      Else
        jppo.Message = vbLf & "Specify the radius or "
        jppo.Keywords.Add("Diameter")
      End If

      jppo.Keywords.Add("Feet")
      jppo.Keywords.Add("Chains")
      jppo.Message += jppo.Keywords.GetDisplayString(True)
      jppo.UserInputControls = UserInputControls.Accept3dCoordinates

      If radius > 0.0 Then
        Dim dist As Double = radius

        If isDiameter Then dist *= 2.0
        jppo.UserInputControls = UserInputControls.Accept3dCoordinates Or UserInputControls.NullResponseAccepted
        jppo.Message += " <" & Autodesk.AutoCAD.Runtime.Converter.DistanceToString(dist) & ">"
      End If

      Dim pr As PromptResult = prompts.AcquireString(jppo)

      Select Case pr.Status
        Case PromptStatus.OK
          retVal = SamplerStatus.OK
        Case PromptStatus.Keyword
          retVal = SamplerStatus.OK
        Case PromptStatus.None
          If radius > 0 Then retVal = SamplerStatus.OK
        Case PromptStatus.Cancel
          retVal = SamplerStatus.Cancel
        Case Else
          Stop
      End Select
    Catch ex As Exception
      ReportError(ex)
    End Try
    Return retVal
  End Function

 

0 Likes
Accepted solutions (1)
559 Views
3 Replies
Replies (3)
Message 2 of 4

ama3UD9K
Explorer
Explorer
Accepted solution

Just want to let everyone know I found a resolution using a IMessageFilter which catches the event.

 

Public Class JigFilter
  Implements IMessageFilter

  Private ReadOnly WM_KEYDOWN As Integer = &H100
  Public EscapePressed As Boolean = False

  Public Function PreFilterMessage(ByRef m As Message) As Boolean Implements IMessageFilter.PreFilterMessage
    Dim retVal As Boolean = False

    Try
      Dim keyInt As Integer = 0
      Integer.TryParse(m.WParam.ToString(), keyInt)

      Dim keyCode As Keys = CType(keyInt, Keys) And Keys.KeyCode

      If m.Msg = WM_KEYDOWN AndAlso keyCode = Keys.Escape Then
        EscapePressed = True
        Return True
      End If
    Catch ex As Exception
      ReportError(ex)
    End Try

    Return retVal
  End Function
End Class
0 Likes
Message 3 of 4

ActivistInvestor
Mentor
Mentor

@ama3UD9K wrote:

Hi everyone,

 

' Must use a string acquire so that we can get the string user input.
' Use the "handlespointmonitor" to save the current point.

 

 

What you wrote above is not true.

 

It's a simple matter to accept arbitrary string input when getting a point. You just set the UserInputControls.AcceptOtherInputString flag.

 

What if the user enters the coordinate input rather than picking a point (which could be polar/cartesian/relative/absolute, etc.).. Where is the code that processes that input and produces a point?

0 Likes
Message 4 of 4

ama3UD9K
Explorer
Explorer

Hi ActivistInvestor for some reason when using AcquirePoint and a JigPromptPointOption and the UserInputControls.AcceptOtherInputString my StringResult would always be null when I used a numerical input which is why I had to change to the AcquireString method.

 

Also there is currently no implementation for a user to enter a coordinate in this routine.

0 Likes