Control config assignments

I am making a custom control setup dialogue and do now know how to
make it wait for the player to press the key they wish to assign.

The way it is set up is using built in GUI with labels for the
action and a button to press to change each one. I want the game
to halt and display “Press any Key” to take their input and assign
it to that action.

I have tried using:

while (!Input.GetKeyDown(KeyCode.Return)) yield;

in this fashion:

if(GUI.Button(new Rect(125,
                 50,
                 60,
                 30),
                 "Choose")) {   

         _displayKeyChoice = true;                     
       }

       // Display key choice
       if(_displayKeyChoice) {

         while (!Input.GetKeyDown(KeyCode.Return)) yield;
       }

But, it returns a parser error and I am not sure why.
Is there a really good way to do this and do you have any suggestions please?

Keycode.Return is the Return key (or Enter). You want to wait for Input.anyKey and then catch the pressed key by checking every Keycode. (in a foreach loop)

I am not sure how to do that.

How do I compare each KeyCode to the captured key?

Does the captured key save into a variable that I can access?

This is where I am with this:

if(_displayKeyChoice1 == true) {
			
			GUI.Label(new Rect(200,					// x
							150,					// y
							100,					// width
							buttonHeight),			// height
							"Press any Key");
			
			if(Input.anyKeyDown) {
				
				// Insert comparisons here?
				
				_displayKeyChoice1 = false;
			}
		}