1

How can I make a clojure program block until a key is pressed?

I want the equivalent behaviour of a blocking read from stdin in other languages.

Drew Noakes
  • 300,895
  • 165
  • 679
  • 742
  • 1
    Yes, it is possible. See http://stackoverflow.com/questions/13435541/reading-unbuffered-keyboard-input-in-clojure – JohnJ Jan 08 '14 at 16:11

1 Answers1

0

The easiest way is to use ConsoleReader from JLine.

See the Clojure Cookbook for details: https://github.com/clojure-cookbook/clojure-cookbook/blob/master/04_local-io/4-02_read-unbuffered-keystroke.asciidoc

The question in JohnJ's comment (Reading unbuffered keyboard input in Clojure) gives a very similar example to the one in the Cookbook.

Community
  • 1
  • 1
A Sammich
  • 366
  • 1
  • 5
  • 13