# Reading characters until the space key is pressed

**URL:** <https://discourse.julialang.org/t/reading-characters-until-the-space-key-is-pressed/123408>\
**Category:** New to Julia\
**Tags:** io\
**Created:** [December 3, 2024, 12:06pm UTC](https://discourse.julialang.org/t/reading-characters-until-the-space-key-is-pressed/123408 "2024-12-03T12:06:45Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![hack3rcon](https://avatars.discourse-cdn.com/v4/letter/h/96bed5/32.png) [@hack3rcon](https://discourse.julialang.org/u/hack3rcon)\
**Post date:** [December 3, 2024, 12:06pm UTC](https://discourse.julialang.org/t/reading-characters-until-the-space-key-is-pressed/123408/1 "2024-12-03T12:06:45Z")

</div>

Hello,  
I want to write a program that receives data from the input and terminates the program as soon as the space key is pressed. I wrote the following program:

```julia
function space()
    print("Please write something: ")
    ch = 'a'
    while ch != ' '
        ch = read(stdin, Char)
    end
end

space()

```

Where is my code wrong?

Thank you.

---

<div class="post-metadata">

**Author:** ![rafael.guerra](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/rafael.guerra/32/216610_2.png) [@rafael.guerra](https://discourse.julialang.org/u/rafael.guerra)\
**Post date:** [December 3, 2024, 12:34pm UTC](https://discourse.julialang.org/t/reading-characters-until-the-space-key-is-pressed/123408/2 "2024-12-03T12:34:22Z")

</div>

You need to use the tricks linked in [this other thread](https://discourse.julialang.org/t/wait-for-a-keypress/20218).

---

<div class="post-metadata">

**Author:** ![hack3rcon](https://avatars.discourse-cdn.com/v4/letter/h/96bed5/32.png) [@hack3rcon](https://discourse.julialang.org/u/hack3rcon)\
**Post date:** [December 4, 2024, 9:32am UTC](https://discourse.julialang.org/t/reading-characters-until-the-space-key-is-pressed/123408/3 "2024-12-04T09:32:56Z")

</div>

Hi,  
Thank you so much.  
Isn’t there an easier way? This is easier to do in other programming languages ​​like C++.
