| | |
Getting Key Input
Please support our C++ advertiser: Intel Parallel Studio Home
![]() |
•
•
Join Date: Aug 2005
Posts: 29
Reputation:
Solved Threads: 0
I know how to use C++ to recieve input via
But now I want a way to constantly check for input without pressing enter.
To my knowledge with cin you must press enter to assign whatever they typed to a variable.
How could I make it so that when the left arrow key is pressed it adjusts a variable (No need to press enter.)
Thank you! (This is console mode)
As an example of what I want to do...When someone pushes down it would add 1 to row_number. If they push up I want it to subtract from row_number.
Same thing with row_column...
As a note all I want is a tutorial or the code to catch the key...Thanks again!
C++ Syntax (Toggle Plain Text)
cin >> x;
But now I want a way to constantly check for input without pressing enter.
To my knowledge with cin you must press enter to assign whatever they typed to a variable.
How could I make it so that when the left arrow key is pressed it adjusts a variable (No need to press enter.)
Thank you! (This is console mode)
As an example of what I want to do...When someone pushes down it would add 1 to row_number. If they push up I want it to subtract from row_number.
Same thing with row_column...
As a note all I want is a tutorial or the code to catch the key...Thanks again!
>To my knowledge with cin you must press enter to assign whatever they typed to a variable.
Correct. Input in standard C++ is line oriented, so to read raw input you need to use a system-dependent or compiler-dependent solution. This is offers three such solutions, but since you didn't tell us what compiler and operating system you're using, I can't help you any better than that.
Correct. Input in standard C++ is line oriented, so to read raw input you need to use a system-dependent or compiler-dependent solution. This is offers three such solutions, but since you didn't tell us what compiler and operating system you're using, I can't help you any better than that.
I'm here to prove you wrong.
•
•
Join Date: Aug 2005
Posts: 29
Reputation:
Solved Threads: 0
•
•
•
•
Originally Posted by Narue
>To my knowledge with cin you must press enter to assign whatever they typed to a variable.
Correct. Input in standard C++ is line oriented, so to read raw input you need to use a system-dependent or compiler-dependent solution. This is offers three such solutions, but since you didn't tell us what compiler and operating system you're using, I can't help you any better than that.
Here is my code
C++ Syntax (Toggle Plain Text)
cout << "Please configure the keys!\nTap Left Now"; int left = getch(); cout << "Tap Right Now\n"; int right = getch(); cout << "Tap Up Now\n"; int up = getch(); cout << "Tap Down Now\n"; int down = getch();
It works nicely except when I push Left it will assign right the same value. How would I stop that? With cin I could do cin.ignore...Is it something similar with this? Thanks!
![]() |
Similar Threads
- Trapping the Tab Key....... (C++)
- school project: simple C++ game (need help with keyboard input) (C++)
- overloaded input stream help (C++)
- how to get the last key pressed without stopping the programm ? (C)
- Problems with first php file (PHP)
- need help with fstream input files (C++)
Other Threads in the C++ Forum
- Previous Thread: counting then deleting multiples!!
- Next Thread: Create log file in Visual C++.NET
| Thread Tools | Search this Thread |
api array based binary bitmap c++ c/c++ calculator char char* class classes code coding compile console conversion count database delete deploy desktop developer directshow dll download dynamic dynamiccharacterarray email encryption error file forms fstream function functions game givemetehcodez google graph gui homeworkhelp iamthwee ifstream input int java lib linkedlist linker linux list loop looping loops map math matrix memory multiple news node number numbertoword output pointer problem program programming project python random read recursion recursive reference return rpg sorting string strings temperature template templates test text text-file tree unix url variable vector video visualstudio win32 windows winsock word wordfrequency wxwidgets






