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

  • Home
  • SEARCH
  • 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 8068003
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T12:31:04+00:00 2026-06-05T12:31:04+00:00

I need to real lines until ESC button is pressed. How can I check

  • 0

I need to real lines until ESC button is pressed. How can I check it?

lines
   = do
      line <- getLine
      if (== "/ESC") --this condition is wrong
         then ...
         else do
            ln <- lines
            return ...

Could anybody fix my problem?

  • 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-06-05T12:31:05+00:00Added an answer on June 5, 2026 at 12:31 pm

    The correct way to escape is with a backslash, the character is '\ESC', so the condition would be

    if line == "\ESC"
    

    But I’m not sure every terminal passes an '\ESC' through to the application.

    If you want to stop immediately when the ESC key is pressed, something along the lines of

    module Main (main) where
    
    import System.IO
    
    main :: IO ()
    main = do
        hSetBuffering stdin NoBuffering
        getUntilEsc ""
    
    getUntilEsc :: String -> IO ()
    getUntilEsc acc = do
        c <- getChar
        case c of
          '\ESC' -> return ()
          '\n' -> do putStrLn $ "You entered " ++ reverse acc
                     getUntilEsc ""
          _ -> getUntilEsc (c:acc)
    

    is what you need. You have to read character-wise, and you need to turn off the buffering of stdin, so the characters are immediately available for reading, and not only after a newline has been entered.

    Note that on Windows turning off buffering didn’t work. I don’t know if this has been fixed recently.
    Also, as @Daniel Wagner reported, it may well be that the Windows command prompt doesn’t pass the ESC to the application.

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

Sidebar

Related Questions

I'm asking this out of curiosity rather than due to a real need to
I am implementing a system where I need real-time updates. I have been looking
I need to print real datbase type name from DbParameter.DbType , but when I
I need to get real world date and time in Java. I use: Date
I need to create a real dynamic JPA CriteriaBuilder . I get an Map<String,
I need help of a real C guru to analyze a crash in my
I need to display a real time data from MS SQL 2005. I saw
I need to find the real type of images, as a lot of times
I need to do an object recognition in real time (with image coming from
I need to be able to map out in coordinates real world cities and

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.