[CE MVBA] How to get user input of ESC

Hello All,

I'd like to get user input of ESC key. Sample codes below:

Sub TestCadInputD() 'record user input
    Dim myCIQ As CadInputQueue
    Dim myCIM As CadInputMessage
    Dim I As Long
    Dim pt3Selection As Point3d
    Set myCIQ = CadInputQueue
    For I = 1 To 1
        Set myCIM = myCIQ.GetInput
        Select Case myCIM.InputType
            Case msdCadInputTypeCommand
                Debug.Print "Command" & vbTab & myCIM.CommandKeyin
            Case msdCadInputTypeReset
                Debug.Print "Reset"
                Exit For
            Case msdCadInputTypeDataPoint
                pt3Selection = myCIM.point
                Debug.Print "Point" & vbTab & pt3Selection.x & vbTab & _
                            pt3Selection.y & vbTab & _
                            pt3Selection.Z & vbTab & _
                            myCIM.View.Index & vbTab & _
                            myCIM.ScreenPoint.x & vbTab & _
                            myCIM.ScreenPoint.y & vbTab & _
                            myCIM.ScreenPoint.Z
            Case msdCadInputTypeKeyin
                Debug.Print "Keyin" & vbTab & myCIM.Keyin
            Case msdCadInputTypeAny
                Debug.Print "Any"
            Case msdCadInputTypeUnassignedCB
                Debug.Print "UnassignedCB" & vbTab & myCIM.CursorButton
        End Select
    Next I
End Sub

Run it in V8i, it will respond user's ESC key and goes to msdCadInputTypeCommand part, debug.print will show "Command INPUTMANAGER TRAINING HINT ".

Run it in CE update 10 V10.10.00.23, if press ESC key, no response, it is waiting for other inputs still.

I didn't revise the ESC in both MS. Actually I don't know if ESC can be customised or not.

Can anyone help me to test the codes in CE update 11? Thanks a lot.

  • Hi Changsong,

    why you want to hook "ESC key pressed" event? It seems it does not fit to standard MicroStation workflow, because ESC has assigned fixed specific functionality.

    Technically it's possible, but in context of this question as well as your former questions (area flood etc.) I guess you use wrong tool (simple limited VBA) to a project that has become quite complex and requires more advanced software tools (at least NET, but better C/C++).

    In NET, I think it's possible to monitor Windows keyboard events (so you do not use MicroStation API, because such does not exist in V8i Interop). In C/C++ I assume it would be possible to monitor MicroStation input queue for the event.

    With regards,

      Jan

  • I have MVBA and I know MVBA only, so I have to use MVBA.

    As per standard windows operation habit, ESC means quit current tool immdiately. I'm trying to let my codes can be quit immediately also, I have achieved it in V8i, but failed in CE updates 10. If it is OK in CE updates 11 or higher (just like area flood problem), it would be OK after we upgrade to CE updates 11, I just need to wait. Otherwise I have to find another way to achieve it.

    Thanks a lot.

  • Hi Changsong,

    I have MVBA and I know MVBA only, so I have to use MVBA.

    this is understandable, but my experience is that it's in fact wrong ... or maybe it's better to say these situations often has no one the best solution.

    It's a bit off-topic, but a tool used to solve some problem should never be based on solely "what I know". What tool/platform/API to use for a particular project is often discussed, because when you do it wrong, you can lost year-man of time and huge amount of money.

    I saw several VBA projects that were either wrong from beginning or have grown in complexity, and because of VBA does not offer professional tools (debuggin, testing, support of Git...) and in code many hacks and tweaks have to be used, authors lost huge amount of time and money to maintain the application. Probably substantially more than they need to learn e.g. VB.NET or C#.

    I'm trying to let my codes can be quit immediately also

    What code? It's crucial to specify the context.

    Is your code primitive or locate command? I guess (but I am not sure) in such case the standard behaviours is maintained by MicroStation automatically.

    Or is it inside some form? In such case it can be more complicated, because VBA forms are not intergated into MicroStation and provides only limited functionality.

    Regards,

      Jan

  • There are differences between professional and amateurs. It is not worthy to spend too many money/energy/time on IT for amateurs, just use current available tool as possible. If the goal is beyond my ability, I will give it up.

    Regarding to the ESC, I have to say ACAD is much more pupular here, and it is ACAD style. I am tryint to let the ACAD users be more familiar with it. I understand that MS is much more powerful than ACAD, but I have accept the fact that most of users here are more familiar with ACAD.

    Sorry I don't understand what's primitive and locate command.

    Some of my codes have form. If there is a form, just click the X to quit it immediately, no need ESC function.

    Thanks a lot.

  • I am tryint to let the ACAD users be more familiar with it.

    It's subjective and I understand why you want to do it this way, but I disagree. A threat here is that you will start to fight with MicroStation standard workflows and hard-coded features and behaviour. But there is some flexible area I guess, where code can works more in AutoCAD way and still do not break MicroStation standard.

    Sorry I don't understand what's primitive and locate command.

    Hmmm, this is one from "core features" in MicroStation programming, including VBA.

    Any tool has to be (exceptions exist, so "it should be") implemented in a sntadardized way. When a tool creates a new element, it's usually classified as PrimitiveCommand (in VBA terminology). When it modifies element(s), it's LocateCommand. Respective interfaces are available in VBA, so it's about to create class implementing one or second interface. When the tool is implemented in this way, it automatically behaves as any standard MicroStation tool (including location, data/reset mouse buttons etc.).

    The same result cannot be implemented in any other way in VBA because of VBA limitations (not only MicroStation VBA, but how the whole VBA works).

    One from problems, which relates to discussed topic "I use VBA for not supported features, so I need to hack / tweak / use key-ints etc.", is that only one tool is active at time. So when VBA code uses key-ins to start another MicroStation tools, own VBA tool it will be canceled. But I have not enough experience (had not to implement it ever) to say how exactly VBA works in this situation.

    Regards,

      Jan

  • ESC means quit current tool immdiately

    Not in MicroStation.  The state-driven input engine doesn't require such a method.

    I don't understand what's primitive and locate command

    The code you are writing events.  Each event is placed in MicroStation's input queue.  You are responsible for managing that queue with a multitude of case statements.

    If you want to simplify your code and at the same time write tools that behave like other MicroStation tools, then learn about IPrimitiveCommandEvents and ILocateCommandEvents.  They are VBA classes that let you create tools that behave like MicroStation tools.  In MicroStation terminology, those are called 'primitive' commands.

    When you write a tool that behaves like MicroStation tools, you don't need ESC. 

    A primitive command always preempts (terminates) another primitive command.  When your user starts a new command, the current command automatically stops.

    There are examples of primitive commands in VBA help.  We've published additional material on our site.

     
    Regards, Jon Summers
    LA Solutions

  • I do not fully understand primitve or locate still. I do both create new element and revise existing element. I don't feel too many differences yet.

    I used "sendcommand" inside my codes sometimes, such as "choose element", even "modify solid". This is the last way if I cannot achive my goal by codes,  then I have to use sendcommand to simulate maual operation.

  • IPrimitiveCommandEvents and ILocateCommandEvents

    I used them seldom. Yes I know they are much better and powerful. I might compile my codes to ActiveX Dll/exe by VB6, not sure if they are OK. So I tend to use simple codes.

    I will study your sample codes. Thanks a lot.