how to use getc (or someting similar) outside of a console

closed account (GNTMDjzh)
i am trying to broaden my horizons of programming, and attempting to make more cross-platform friendly programs. instead of using a direct x wrapper, openGL, instead of a windows only input library, i am trying to use just the c++ standard library for detecting key presses. however, unless i am running a console, no key-presses are picked up. i have tried getc(stdin), getchar, fgetc(stdin), and all come back with -1 every time regardless of the state of the keyboard. do i really have to use an API for keyboard input?
Without directly hooking the keyboard driver I'm going to have to say yes.
Signals go from keyboard -> into machine -> handled by driver -> accessed by api's -> accessed by programmers.

Things such as Direct X and OpenGL go under the api I believe, so with enough research you could do the same.

But as far as I know you won't be able to use standard IO libraries to do what your trying to do.
The console window handles events, and/or polls to detect input. It may seem low level, but its still pretty high. Libraries are written for programmer ease of use.

My lower level knowledge is pretty limited, so I don't really want to say to much more.

Generally when your trying to write cross platform code, and use the same set of code, you use code segments to determine the operating system and point it to execute seperate code sets. A simpler example could be using javascript to display different css on different browsers and resolutions.

I am sure there are libraries that do what your trying to do already. Though that doesn't help in the area of broadening your knowledge ;/

I'll be watching this thread, hopefully some of the more knowledged people will provide some interesting input =P
do i really have to use an API for keyboard input?


Yes.

That doesn't mean you can't use a crossplatform API. Widgetry libs (wx, Qt, FLTK, etc) have their own way to handle input, and gaming libs (SFML, SDL, etc) have their own way to handle it.

I'd recommend picking such a lib up.
Topic archived. No new replies allowed.