[Question]
  [
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 [code-golf](/questions/tagged/code-golf "show questions tagged 'code-golf'"), 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.
  
[Answer]
## Batch, 46 bytes
```
@echo Press any key to continue...
@pause>nul
```
Because `pause`'s output contains a space before each `.`.
[Answer]
# HTML + JavaScript (ES6), 36 + 25 = 61 bytes
You can't really exit a JavaScript program, so clearing the webpage is the best I can think of.
```
onkeyup=_=>a.innerHTML=''
```
```
<a id=a>Press any key to continue...
```
---
# HTML + JavaScript (ES6), 33 + 28 = 61 bytes
Alternate solution [suggested by @LarsW](https://codegolf.stackexchange.com/questions/107709/press-any-key-to-continue/107750?noredirect=1#comment262098_107750) that redirects to `about:blank`.
```
onkeyup=_=>location='about:blank'
```
```
Press any key to continue...
```
---
# HTML/JavaScript, 60 bytes
Another awesome solution [by @Ismael Miguel](https://codegolf.stackexchange.com/questions/107709/press-any-key-to-continue/107750?noredirect=1#comment262407_107750) that doesn't use standalone JS. 1 byte saved!
```
<html onkeyup=this.innerHTML=''>Press any key to continue...
```
---
# HTML + JavaScript (ES6), 26 + 28 = 54 bytes
Yet another solution [by @George Reith](https://codegolf.stackexchange.com/questions/107709/press-any-key-to-continue/107750?noredirect=1#comment262736_107750) making use of document writes.
```
onkeyup=_=>document.open()
```
```
Press any key to continue...
```
# HTML + JavaScript (ES7), 23 + 28 = 51 bytes
Same program using the [proposed ES7 bind operator](https://github.com/tc39/proposal-bind-operator):
```
onkeyup=::document.open
```
```
Press any key to continue...
```
---
As most of these solutions are not my own, do a courtesy and vote them up in the comments!
[Answer]
# MATL, 35 bytes
```
'Press any key to continue...'D0$Y.
```
**Explanation**
```
'Press any key to continue...'      % String literal
D                                   % Display the string (has trailing newline)
0$Y.                                % Pause until the user presses any key
```
[Answer]
# TI-Basic, 55 bytes
Basically, it loops until a key is pressed. Too bad lowercase letters are two bytes each in TI-Basic...
```
Disp "Press any","key to continuesin(
Repeat getKey
End
```
P.S. See the comment by @GoldenRatio for the explanation as to how this works. It's genius!
[Answer]
# Bash, ~~46~~ ~~43~~ 42 bytes
*Saved 1 byte thanks to @DigitalTrauma*
```
read -rn1 -p"Press any key to continue..."
```
Uses the `read` built-in. `-r` makes sure it doesn't allow the user to input escapes. `-n 1` allows just one character. `-p` is the prompt
[Answer]
# [Haskell](https://www.haskell.org/), ~~51~~ 50 bytes (Thanks @villou24)
```
main=putStr"Press any key to continue...">>getChar
```
[Try it online!](https://tio.run/nexus/haskell#@5@bmJlnW1BaElxSpBRQlFpcrJCYV6mQnVqpUJKvkJyfV5KZV5qqp6enZGeXnlrinJFY9P8/AA "Haskell – TIO Nexus")
[Answer]
## SmallBasic, ~~18~~ 17 bytes
* Version 2.0
17 bytes
```
TextWindow.Show()
```
* Version 1.0
18 bytes
```
TextWindow.Pause()
```
[Answer]
# Octave / MATLAB, 42 bytes
```
disp('Press any key to continue...');pause
```
[Answer]
# QBasic ([QB64](http://qb64.net)), 37 (42?) bytes
Unfortunately, QBasic's built-in end-of-program prompt doesn't have the ellipsis, so we'll have to print it ourselves:
```
?"Press any key to continue..."
SLEEP
```
(`SLEEP` without an argument waits until a keypress.)
This code does what the question literally asks for, but it doesn't seem like it fits the spirit of the question because, of course, QBasic then displays "Press any key to continue" and waits for a keypress before returning to the IDE. Here's one that goes straight to the IDE, for +5 bytes:
```
?"Press any key to continue..."
SLEEP
STOP
```
`STOP` is a debugging statement. In regular QBasic, it sets a breakpoint: execution halts and we return to the IDE, but execution can be resumed again with F5. It's unclear whether that would count as the program "exiting." However, I'm using the QB64 emulator, which can't do breakpoints. Upon encountering `STOP`, it simply halts--returning straight to the IDE without the redundant "Press any key" message.
[Answer]
# Processing, ~~89~~ 81 bytes
```
void setup(){print("Press any key to continue...");}void draw(){if(key>0)exit();}
```
### Explanation
```
void setup(){print("Press any key to continue...");}
```
This is required since I am using more than one function in my program. Anything inside `setup()` gets called, in this case the string `"Press any key to continue..."`.
```
if(key>0)exit();
```
Checks if `key` (`key` will always contain the int value of the last key pressed) is more than `0` (ie not a null byte). If the condition is satisfied, then the program exits.
```
void draw(){}
```
`draw()` ensures that that the program will always keep looking for a key instead of stopping once the program starts.
(That feel when a builtin in a Java-like language is still verbose...)
[Answer]
# Pascal, ~~75~~ 65 bytes
This was tested with the Free Pascal Compiler, version 3.0.0.  
It may work with TurboPascal 7 or newer.
```
uses Crt;begin write('Press any key to continue...');readkey;end.
```
Sadly, I can't replace `readkey` with `readln` since the challenge requires that **any** key be accepted.
---
I've tested this code on <http://rextester.com/l/pascal_online_compiler>, with and without supplying an input.  
As expected, the program is terminated after 10s, since it sits waiting for a keypress that never happens.
---
Thanks to [@manatwork](https://codegolf.stackexchange.com/users/4198/manatwork) for saving me 10 bytes by proving me wrong, and showing that I don't need the `program _;`.
[Answer]
# Scratch, 81 bytes
![image](https://i.stack.imgur.com/A4PQE.png)
```
when gf clicked
say [Press any key to continue...
wait until <key [any v] pressed
```
([Scratchblocks link](http://scratchblocks.github.io/#when%20gf%20clicked%0Asay%20%5BPress%20any%20key%20to%20continue...%0Await%20until%20%3Ckey%20%5Bany%20v%5D%20pressed))
If you wanted it to stop the *entire* program when you pressed a key (including other threads) you'd have to add a `stop all`. If you want to get rid of the say dialog you need an empty `say` block (`stop all` works as well).
Convenient that Scratch has a builtin for this!
[Answer]
## Bash ~~48~~ ~~44~~ 42 bytes
```
read -rn1 -p"Press any key to continue..."
```
@mame98 Thanks for saving 4 bytes.
@RaisingAgent Thanks for saving 2 bytes.
[Answer]
# Python 2, 110 bytes
```
import curses as c
s=c.initscr()
c.cbreak()
s.addstr(0,0,'Press any key to continue...')
while not s.getch():1
```
[Answer]
## R, 56 bytes
```
cat('Press any key to continue...');keypress::keypress()
```
This works in Linux and OSX terminals.
[Answer]
# Ruby (2.3) (+ Batch), ~~52~~ ~~55~~ ~~54~~ ~~53~~ 46 bytes
Now 46 bytes thanks to Alexis Andersen.
Note: Tested on Windows, might not work if there is no `pause` command.
```
puts"Press any key to continue...";`pause>nul`
```
# Explanation
`Puts` the required text:
```
puts"Press any key to continue..."
```
End the line:
```
;
```
Run the Batch `pause` command and pipe output to `nul`:
```
`pause>nul`
```
[Answer]
# Java, 127 bytes
```
class P{public static void main(String[]a)throws Exception{System.out.print("Press any key to continue...");System.in.read();}}
```
Note: [the console must be set to raw mode](https://stackoverflow.com/q/1066318/) in order for this to work.
[Answer]
# SmileBASIC, 52 bytes
```
?"Press any key to continue...
WHILE""==INKEY$()WEND
```
[Answer]
# Mathematica, 62 bytes
```
EventHandler["Press any key to continue...","KeyDown":>Exit[]]
```
**Explanation**
```
EventHandler["Press any key to continue...","KeyDown":>Exit[]]
EventHandler[                                                ]  (* Create a new EventHandler *)
             "Press any key to continue..."                     (* Print the dialog text *)
                                            "KeyDown":>Exit[]   (* When a key is pressed down, exit *)
```
[Answer]
# SmileBASIC, 55 bytes
```
?"Press any key to continue..."@L IF INKEY$()!=""GOTO@L
```
Explained:
```
?"Press any key to continue..."  '? means PRINT
@L                               'start of loop
IF INKEY$()!="" GOTO @L          'if no key pressed goto @L
```
[Answer]
# Python 2/3 POSIX, 85 bytes
```
import sys,tty
print('Press any key to continue...')
tty.setraw(1)
sys.stdin.read(1)
```
[Answer]
# **Python 3, 65 bytes**
Requires the Windows version of Python.
```
from msvcrt import*
print("Press any key to continue...")
getch()
```
msvcrt.getch() doesn't wait for the enter key to be pressed like input(), it returns the first key pressed.
Python Docs for msvcrt.getch():
<https://docs.python.org/3/library/msvcrt.html#msvcrt.getch>
Thanks to @Fliptack for saving some bytes
[Answer]
# Node.js, ~~102~~ ~~101~~ 99 bytes
```
with(process)stdout.write('Press any key to continue...'),s=stdin,s.setRawMode(1),s.on('data',exit)
```
[Answer]
# Sinclair ZX81/Timex TS1000 BASIC: Method 1 approximately 41 bytes
```
1 PRINT "PRESS ANY KEY TO CONTINUE..."
2 GOTO (INKEY$<>"")+VAL "2"
```
## Method 2 approximately 38 BYTES
```
1 PRINT "PRESS ANY KEY TO CONTINUE..."
2 PAUSE VAL "4E4"
```
I prefer method 1 as on the ZX81, there is a screen flicker when `PAUSE` is called, and if you want long enough (providing the ZX81 doesn't overheat or crash) the pause will eventually come to an end, whereas method 1 is stuck in an infinite loop until a key is pressed, and no screen flicker.
I'll work out the correct number of bytes used later when I have the right bit of BASIC that will tell me. By the way, using VAL "x" instead of the number saves valuable RAM on a ZX81 (I think that this is the same for the ZX Spectrum as well).
[Answer]
## Perl 5, 79 bytes
```
system "stty cbreak";$|=1;print "Press any key to continue...";read(STDIN,$a,1)
```
used as:
```
perl -e 'system "stty cbreak";$|=1;print "Press any key to continue...";read(STDIN,$a,1)'
```
No prizes of course. I'm sure some perl person will have a better way.
(89 bytes if the interpreter invocation as well needs to be included in the count)
[Answer]
### PHP, 73 bytes
```
echo"Press any key to continue...";$h=fopen("php://stdin","r");fgets($h);
```
Run it in the PHP interactive shell (`php -a`)
[Answer]
# C#, 101 bytes
```
using C=System.Console;class P{static void Main(){C.Write("Press any key to continue...");C.Read();}}
```
Tested on Linux, should run on any system having the .NET libraries and the Common Language Runtime.
Ungolfed program:
```
using C = System.Console; // creating a shorter alias for the System.Console class
class P
{
    static void Main()
    {
        C.Write("Press any key to continue...");    // prints the message
        C.Read();   // waits for key press
    }
}
```
CTRL, ALT, SHIFT are ignored. The pressed key will be echoed on screen if printable.
Echo can be disabled by replacing *C.Read()* with *C.ReadKey(0<1)* at the cost of 6 more bytes.
[Answer]
# [8th](http://8th-dev.com/), 47 bytes
```
"Press any key to continue..." . cr con:key bye
```
This program ignores keys like ctrl, alt, caps lock. Quits with keys like letters, numbers, symbols, and enter.
**Explanation**
```
"Press any key to continue..." . cr \ Print message 
con:key                             \ Wait for key input from console  
bye                                 \ Quit program 
```
[Answer]
## C#, 29 bytes
```
class P{static void Main(){}}
```
Not sure if this is considered valid because it prints:
> 
> Press any key to continue . . .
> 
> 
> 
But there is a [Batch](https://codegolf.stackexchange.com/a/107804/38550) answer that prints this as well.
[Answer]
# Forth (gforth), 39 bytes
```
." Press any key to continue..."key bye
```
(Yes, there is already an 8th solution but this is shorter)
]