The easiest way to get real-time key state on Windows is with GetAsyncKeyState:
1 2 3 4
if(GetAsyncKeyState('A') & 0x8000)
// the 'A' key is currently being held down
How to do this for all systems (Windows, Linux, Mac,...)?
There is no standard solution that works on all systems. If you want crossplatform support, you'll need an additional library. Libraries like SFML, SDL, wx, Qt, ncurses all have keyboard polling support.
I already searched but only found a Windows solution and something about key-codes, are those 'codes' the same on all systems?
Absolutely not. Every OS works completely differently.
If you want portability across multiple OS's, then you want an external lib like the above mentioned ones. They provide a simplistic interface that works on multiple OS's