

Task

Obtain a valid   Y   or   N   response from the keyboard.

The keyboard should be flushed, so that any outstanding key-presses are removed, preventing any existing   Y   or   N   key-press from being evaluated.

The response should be obtained as soon as   Y   or   N   are pressed, and there should be no need to press an   enter   key.




handler YesOrNoHandler type RUIhandler{initialUI =[ui], onConstructionFunction = start}
 
    ui Div { };
 
    const KEY_N int = 78;
    const KEY_Y int = 89;
 
    function start()
    	document.onKeyDown = d_onKeyDown;
    end
 
    function d_onKeyDown(e Event in)
 
	case (e.ch)
  	    when (KEY_N)
	        ui.innerText = "N pressed.";
	    when (KEY_Y)
	        ui.innerText = "Y pressed.";
	end
 
	e.preventDefault();
 
    end
 
end