Search code examples
user-interfacescripting3dsmaxmaxscript

Basic MaxScript GUI operations: how do I get the Enter key? How do I grey out controls?


Apologies for the kind-of unrelated questions in one, but I would like to make my MaxScript rollout/tool more intuitive by making it behave like any other GUI would be expected to.

Could anyone familiar with MaxScript tell me:

  1. How do I 'disable' (grey out) a button?

  2. How do I get the Enter key pressed event? (I.e. I have an EditText control. When enter is pressed anywhere in this form I would like to close the dialog (it is not a multiline control))

  3. How do I give focus to a control? (I.e. I would like my rollout opened with CreateDialog to give focus to the EditText control so the user can start typing immediately)


Solution

  • the first one would be setting its .enabled property to false. The second one depends on the type of control you are using, if it's the usual rollout control, just use on editTextName entered do ... event handler. For a dotnet one you'd have to use

        on editTextName KeyUp evnt do
            if evnt.KeyCode == (dotNetClass "System.Windows.Forms.Keys").Enter do ...
    

    As for the third one, use setFocus method in your rollout open event handler:

        on myRollout open do setFocus editTextName
    

    Hope this is what you were looking for.