Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 909553
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T16:53:50+00:00 2026-05-15T16:53:50+00:00

How can I read a single character/key from the console without having to hit

  • 0

How can I read a single character/key from the console without having to hit Enter? There is an old entry in Sun’s bug database claiming that it can’t be done in pure java. I’ve found these approaches

  • JNI
  • JLine [http://jline.sourceforge.net/]
  • Javacurses [http://sourceforge.net/projects/javacurses/]

I’d expect to add a single magic-readkey.jar to my classpath, and to write a few lines of code, like (def just-hit (com.acme.MagicConsole/read-char)).

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-15T16:53:51+00:00Added an answer on May 15, 2026 at 4:53 pm

    Here’s an “immediate echo” app using JLine which will print ints corresponding to registered keypresses, structured as a Leiningen project:

    1. project.clj:

      (defproject con "1.0.0-SNAPSHOT"
        :description "FIXME: write"
        :main con.core
        :dependencies [[org.clojure/clojure "1.1.0"]
                       [org.clojure/clojure-contrib "1.1.0"]
                       [jline "0.9.94"]])
      
    2. src/con/core.clj:

      (ns con.core
        (:import jline.Terminal)
        (:gen-class))
      
      (defn -main [& args]
        (let [term (Terminal/getTerminal)]
          (while true
            (println (.readCharacter term System/in)))))
      

    The functionality in question is provided by the jline.Terminal class, which provides a static method getTerminal returning an instance of a platform-specific subclass which can be used to interact with the terminal. See the Javadoc for more details.

    Let’s see what asdf looks like…

    $ java -jar con-1.0.0-SNAPSHOT-standalone.jar 
    97
    115
    100
    102
    

    (C-c still kills the app, of course.)

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.