36
\$\begingroup\$

Your task is to create a program that will display the following text, wait for the user to press a key (it is okay to ignore keys like ctrl, alt, caps lock, etc., as long as keys like letters, numbers, symbols, and enter are not ignored), and then terminate the program:

Press any key to continue... 

Trailing newlines are allowed. The program must exit immediately after a key is pressed. Also, the program must be fairly portable (i.e no OS-specific headers or modules, runs outside of an IDE, etc.).


The prompt must be exactly as shown above, unless a trailing newline cannot be avoided.


This is , so the shortest answer in bytes wins. This is also my first code-golf question, so I apologize if I do not know the rules on PPCG.

\$\endgroup\$
16
  • 4
    \$\begingroup\$ Is the output text case sensitive? Would WinBatch PAUSE be a valid answer (ellipsis is spread from ... to . . .)? \$\endgroup\$
    – FlipTack
    Jan 22, 2017 at 18:40
  • 13
    \$\begingroup\$ Also I'd suggest waiting for a week or 2 before accepting any answer \$\endgroup\$
    – user41805
    Jan 22, 2017 at 18:59
  • 3
    \$\begingroup\$ Most language's pause functions are probably insensitive to keys like Caps-Lock or Control (pressed on its own). Maybe you should clarify if the program is allowed not to notice those keys \$\endgroup\$
    – Luis Mendo
    Jan 22, 2017 at 19:11
  • 15
    \$\begingroup\$ You should wait for a few weeks before accepting an answer, as countless others have advised you (yet you've chosen to ignore their advice) \$\endgroup\$
    – FlipTack
    Jan 22, 2017 at 19:12
  • 12
    \$\begingroup\$ @JungHwanMin I agree with others. Please wait to accept a solution until entries have stopped rolling in. I really don't enjoy riding the Reputation Roller Coaster \$\endgroup\$
    – Suever
    Jan 22, 2017 at 19:13

34 Answers 34

1
2
1
\$\begingroup\$

SmallBasic 17 bytes

TextWindow.Show()

I had this answer before the accepted answer added it to their answer by the way. (To avoid unjust flags)

\$\endgroup\$
1
  • \$\begingroup\$ Comments are not for extended discussion; this conversation has been moved to chat. \$\endgroup\$
    – Dennis
    Feb 15, 2017 at 16:33
0
\$\begingroup\$

MATLAB, 41 bytes

or it could be Octave, 40 bytes.

This is quite similar to the obvious approach posted by Suever, but is one glorious byte shorter.

disp 'Press any key to continue...'
pause

or in Octave:

disp"Press any key to continue..."
pause

A little known and little used feature of both MATLAB and Octave is that most builtin functions can be called without parentheses, in which case they will treat whatever follows it as a string (as long as it doesn't contain spaces).

For instance:

nnz PPCG
ans = 4

size PPCG
ans = 1  4

str2num 12
ans = 12

Now, if the input is a word with multiple words, then we need the quotation marks, so disp('Press any key to continue...') is reduced to disp 'Press any key to continue...', saving one byte. Instead of the semicolon separating the disp call and the pause, we now separate them using a linefeed.

\$\endgroup\$
0
\$\begingroup\$

C64Mini/C64 BASIC (also VIC-20 BASIC) 52 tokenized BASIC bytes

 0?"PRESS ANY KEY TO CONTINUE...":POKE198,0:WAIT198,1

The ? is short-hand for PRINT; thereafter, POKE 198,0 will clear the keyboard buffer, whilst WAIT 198,1 will wait until the keyboard buffer has something in it again.

Because the keyboard buffer isn't cleared whatever key is struck when the program executes is displayed. You may tidy this up with another 4 BASIC tokens by adding :GETA$ to the end of line zero.

The screen shot shows the VIC-20 in action, which by default only has a 22 column display source

VIC-20 "Press any key to continue" program

\$\endgroup\$
0
\$\begingroup\$

HTML + Javascript, 58 bytes

<html onkeyup=document.open('')>Press any key to continue.

\$\endgroup\$
1
2

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.