![]() |
|
![]() |
|
|
Thread Tools | Display Modes |
|
|
#1 |
|
Newbie
Join Date: Nov 2006
Posts: 5
Rep Power: 0
![]() |
Need help with user input
Hey all,
I'm making a small console game, and I'm looking for another way to get users input. I'm using the WASD keys to move a cursor on the screen, but the only way I know to get a users input is by using cin. As you can guess, having to press a direction key and then hit Enter is a bit time consuming on the users side and I was wondering if anyone can give me some help in finding another way to do this. I know this can be accomplished using ncurses, and probably other libraries. But I'd really like to stick with the standard C++ libraries if possible. Oswyn |
|
|
|
|
|
#2 |
|
Programming Guru
![]() Join Date: Jun 2005
Location: Adelaide, South Australia
Posts: 1,198
Rep Power: 5
![]() |
Not possible. There is no way in the standard C or C++ libraries to receive individual keystrokes. That's because the standard libraries are based around a pretty generic computing device (and, generically, a computing device may not have a keyboard).
If you are targeting a machine with a keyboard, most compilers you will be using and their libraries include functions that provide some means of obtaining keystrokes directly. You need to read your compiler and library documentation to find out how to do it. Keep in mind that the method varies between compilers and systems. If you want to use curses or similar, look up raw input. |
|
|
|
|
|
#3 |
|
Newbie
Join Date: Nov 2006
Posts: 5
Rep Power: 0
![]() |
I was afraid that would be the case. I looked over some curses examples and came up with this, a pretty minimal solution, in case anyone is interested.
#include <ncurses.h>
int main() {
initscr();
raw();
noecho();
char ch;
while(!ch || ch != 'x') {
ch = getch();
printw("You pressed: %c \n", ch);
}
return 0;
} |
|
|
|
|
|
#4 | |
|
Programming Guru
![]() Join Date: Jun 2005
Location: Adelaide, South Australia
Posts: 1,198
Rep Power: 5
![]() |
Quote:
|
|
|
|
|
![]() |
| Bookmarks |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | |
| Display Modes | |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| User input | jayme | C++ | 38 | Nov 25th, 2005 7:27 PM |
| FiveDigit + RandomeNumber Game. | TecBrain | Java | 0 | Nov 18th, 2005 2:53 PM |
| User Input for Number Format | ericelysia1 | Java | 0 | Jul 21st, 2005 3:41 PM |
| Problem read'ing from file and user input | jmsilver | Bash / Shell Scripting | 3 | May 20th, 2005 2:35 PM |
| Instant Messaging App Help | AusTex | C | 0 | Apr 27th, 2005 4:52 PM |