Forum > Beginners

Press Any Key to Begin?

(1/1)

mgarurumon:
Hello! I have this blinking "PRESS <ANY KEY/ENTER> TO BEGIN."


--- Code: Pascal  [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---repeat  writeln ('                       PRESS <ANY KEY/ENTER> TO BEGIN');  GotoXY(1,15); delay(1500); DelLine; delay(750); GotoXY (1,15);until KeyPressed = true; cursoron;end;    clrscr;writeln;writeln ('What is your name?');readln (PlayerName);  
but I don't want whatever pushed to appear~ for example, if "j" was to be pushed by the user, I don't want that to appear in the line when the program is reading the PlayerName. I think what I'm aiming for is either suppressing the input of the KeyPressed or a different loop that would allow me to have that blinking text until the input was 'Enter.'

Could anyone please help me figure this out? :) Thank you!

bylaardt:

--- Code: Pascal  [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---repeat  writeln ('                       PRESS <ANY KEY/ENTER> TO BEGIN');  GotoXY(1,15); delay(1500); DelLine; delay(750); GotoXY (1,15);until KeyPressed = true; cursoron;end;  readkey;  // insert this line hereclrscr;writeln;writeln ('What is your name?');readln (PlayerName); 

Bart:
Better:

--- Code: ---  while KeyPressed do ReadKey;

--- End code ---

Why?
If user presses a function key, there are 2 keys in the keyboard buffer, and your code only "eats" one.

(At least that's how it used to be in the old TurboPascal days).

Bart

mgarurumon:
Thank you so much for teaching me! It totally makes sense now!  :D

Navigation

[0] Message Index

Go to full version