+ 2

C input without waiting for user to press enter

Hi everyone I want create mini game with c I want it to immedietly read character from keyboard as it typed in console without waiting for user to press enter button Any idea how to do that ?

3rd Mar 2019, 6:06 PM
AliR૯za
AliR૯za - avatar
16 odpowiedzi
+ 11
You can use getch() or getche() functions defined in the conio.h library. For more information and difference between these two functions, check out the link below: https://www.quora.com/What-are-the-uses-of-getche-in-C++
3rd Mar 2019, 6:48 PM
blACk sh4d0w
blACk sh4d0w - avatar
+ 6
Aaron Eberhardt Ok thank you 🙏
3rd Mar 2019, 6:53 PM
AliR૯za
AliR૯za - avatar
+ 6
its in library called conio.h #include <conio. h> getch(); or getchar() ;
3rd Mar 2019, 7:06 PM
Anon Fox
Anon Fox - avatar
+ 5
nAutAxH AhmAd Thank you for reference 🙏
3rd Mar 2019, 6:55 PM
AliR૯za
AliR૯za - avatar
+ 4
AliR૯za I've had the same doubts in the past. Although getch() works, remember that it isn't standard C++ (and hence whatever isn't should be avoided if possible). Some has claimed that std::cin.get() or getchar() can be feasible replacements, but these functions do echo the keyboard hit onto the terminal. If you have to use getch(), just keep in mind the cons that come along. https://www.sololearn.com/Discuss/210329/?ref=app https://www.sololearn.com/Discuss/302236/?ref=app
3rd Mar 2019, 10:58 PM
Hatsy Rei
Hatsy Rei - avatar
+ 4
Aaron Eberhardt 👍 Thanks for reference
4th Mar 2019, 9:51 AM
AliR૯za
AliR૯za - avatar
+ 4
Hatsy Rei Ok ,thank you
4th Mar 2019, 10:01 AM
AliR૯za
AliR૯za - avatar
+ 3
What you might want is usually called raw input because it won't be buffered nor processed by the OS. While reading the other answers I was a little surprised that Windows can't offer such simple solutions as Linux. However when looking for raw input on Windows I found this page: https://docs.microsoft.com/en-us/windows/desktop/inputdev/raw-input Maybe it's a bit complicated to use but it should be the best standardized solution for Windows.
4th Mar 2019, 6:24 AM
Aaron Eberhardt
Aaron Eberhardt - avatar
+ 2
Which OS do you use? Input will be handled differently depending on that...
3rd Mar 2019, 6:31 PM
Aaron Eberhardt
Aaron Eberhardt - avatar
+ 2
With Windows I have no experience...
3rd Mar 2019, 6:47 PM
Aaron Eberhardt
Aaron Eberhardt - avatar
+ 2
🇮🇷 M N سلام دقیقا همونیه که میخواستم ممنونم❤
3rd Mar 2019, 6:54 PM
AliR૯za
AliR૯za - avatar
+ 1
Aaron Eberhardt I want it for windows
3rd Mar 2019, 6:34 PM
AliR૯za
AliR૯za - avatar
3rd Mar 2019, 6:50 PM
🇮🇷 M N
0
Hatsy Rei Aaron Eberhardt 🇮🇷 M N Hi,Sorry for bothering you again my friends You are always helping me in c/c++ problems 🙏 & in this case if you have any idea or refrences i will happy to see them,thank you🙏
3rd Mar 2019, 6:22 PM
AliR૯za
AliR૯za - avatar