Enter is usually equivalent to C-m. But, if the icrnl
flag is active for the tty (see stty -a
), then an input C-m will automatically be translated to C-j (so that it is easy to type Unix-ly terminated lines by just pressing Enter).
In plain C you could use the termios functions tcgetattr(3) and tcsetattr(3) to unset the ICRNL flag in c_iflag
so that C-m is not translated to C-j on input. If you want absolute control over the input and output, you would use a “raw” mode (disable all input and output processing). It looks like Python has these termios functions.
The curses library has some higher-level functions for dealing with tty modes: savetty(3), resetty(3), nonl(3), raw(3), cbreak(3), etc. It also looks like Python has these curses functions.
If you are using other bits of the curses library, then it is probably best to also use its functions to adjust the ICRNL flag (e.g. nonl(3)) to avoid breaking any assumptions that the library has made (i.e. it assumes the tty is set one way, but your termios-level calls change things and break that assumption).