"silent" input in C# (noecho style)

In this simple script, I would like to hide the letters typed by the user during the GetString input:

using System;
using Rhino;
using Rhino.UI;

bool keyPressed = false;
RhinoApp.KeyboardEvent += OnKeyboardEvent;

bool result = PauseForEnter();
RhinoApp.KeyboardEvent -= OnKeyboardEvent;
RhinoApp.WriteLine(result?"Comand confirmed":"Command canceled");

void OnKeyboardEvent(int key)
{
        if (!keyPressed)
        {
            keyPressed = true;
            return;
        }
        else
        {
            switch(key)
            {
                case (int)KeyboardKey.A:
                {
                    RhinoApp.WriteLine("action A");
                    break;
                }
                case (int)KeyboardKey.D:
                {
                    RhinoApp.WriteLine("action D");
                    break;
                }
            }
            keyPressed = false;
        }
}

bool PauseForEnter()
{
    string outputString = string.Empty;
    string prompt = "Press A-D for actions, spacebar or ENTER to confirm, ESC to exit";
    var result = Rhino.Input.RhinoGet.GetString(prompt, true, ref outputString);
    return (result!=Rhino.Commands.Result.Cancel);
}

Basically, hide those “aaaddaaadda” characters typed in input:

2025-10-28 12_13_20-TestOrientBlockFromHandle.3dm (164 KB) - Rhino 8 Educational - Perspective

Is this possible somehow? I’ve searched the documentation, examples and forum to no avail so far.

Hi @ale2x72,

NoEcho only works when scripting commands. For example:

_NoEcho _-Layer _New "Alessio" _Enter

As far as I know, there is no way to suppress what the user types from appearing on the command line while in a GetString operation.

Why do you need this?

– Dale

Because that trail of characters in the command line is an eyesore and can confuse the user

How about this?

protected override Result RunCommand(RhinoDoc doc, RunMode mode)
{
  GetOption go = new GetOption();
  go.SetCommandPrompt("Select an action");
  go.AcceptNothing(true);

  int a_index = go.AddOption("A");
  int b_index = go.AddOption("B");
  int c_index = go.AddOption("C");
  int d_index = go.AddOption("D");

  while (true)
  {
    GetResult res = go.Get();

    if (res != GetResult.Option)
      break;

    CommandLineOption option = go.Option();
    if (null != option)
    {
      if (option.Index == a_index)
        RhinoApp.WriteLine("Action A selected");
      else if (option.Index == b_index)
        RhinoApp.WriteLine("Action B selected");
      else if (option.Index == c_index)
        RhinoApp.WriteLine("Action C selected");
      else if (option.Index == d_index)
        RhinoApp.WriteLine("Action D selected");
    }
    continue;
  }

  return Result.Success;
}

– Dale

Thank you Dale, but this is not what I’m looking for.

With GetOption, an action is triggered by pressing KEY+ENTER or KEY+SPACEBAR, while I want the action to be triggered by the relative key alone. This is because those keys cycle through options (for example: W is “rotate object +90 degrees”, S is “rotate object -90 degrees”), and those options might be cycled through very quickly and frequently, so adding an extra key to press every time an action is triggered breaks immediacy and intuitiveness.

Anyways, if hiding those keypresses is not possible it’s not a huge deal, I was only wondering whether I missed something. Maybe an option to hide the Command line output when capturing Keyboard events could be an idea for future versions of RhinoCommon.