Is there a standard way to capture keyboard inputs that works in a c++ application for linux and windows?

248 Views Asked by At

For a c++ game so it can run on a linux machine or windows machine?

Like with windows I would use hooks but I wondered how I can do the same thing so my game can run on linux machines too?

1

There are 1 best solutions below

0
On

Use a library to abstract the differences between platforms.

If you are writing a simple console-based application, then the C++ standard library is enough. For a graphical application, you will want to use something like LibSDL. It is common for games to use SDL. This allows the same game to run on Windows, Linux, and OS X without too much modification between platforms.

GLFW and SFML are some other alternatives.

If are writing a complex console-based application, like NetHack, you will need a library for console abstraction such as ncurses.