What language are we talking about (Online GDB supports multiple languages).
If it's C, have a look at this: https://stackoverflow.com/questions/20349585/c-library-function-to-check-the-keypress-from-keyboard-in-linux
Most of the time, this is done via some platform-dependent library as the C standard doesn't have a proper key hit detection defined (the closest one is reading one character --getchar -- from the stdin)