Use a different terminal?
You see, the problem is that your program receives all keystrokes and other events *from* the terminal, and the terminal from the desktop environment. The terminal doesn't "steal" them, it just does not forward them to your program.
Normally, we just avoid keys typically used by the desktop environment.
The only portable solution, really, is to let the user override the key codes. In Linux, *BSD, and Unix systems it is common to store those as a text file in
$HOME/.yourprogram.rc or
$HOME/.yourprogram/keys . In Windows, there's a similar directory elsewhere (don't know the exact recommended one offhand, but it was something about Application Settings). Typically the format is human readable, something like
Code:
KEY_Menu = F1
KEY_Quit = Ctrl-Q
KEY_Load = Ctrl-O
KEY_Copy = Ctrl-C
KEY_Cut = Ctrl-X
KEY_Paste = Ctrl-V
Of course, parsing these files is a bit of a pain in the butt, since you have to do it yourself -- it's not at all complicated, just a lot of code (if clauses or arrays with Curses key constants). Fortunately, the Curses constants (like
F(1) ) won't change while the program is running, so you only need to do the parsing once, at the beginning of your program.
Many Unix/Linux/BSD programs support multiple such configuration files; one for distribution defaults (say,
/usr/share/yourprog/keys), one for system-specific overrides (say,
/etc/yourprog/keys), and one for the user-specific overrides (say,
$HOME/.yourprog/keys), read in this order, with missing files ignored. This is because Unix/Linux/BSDs are inherently multi-user systems. One solution is to have an array of locations tried, and just populate it differently on different architectures.
To expand the environment variable references in config file paths, UNIX/Linux/BSD systems often use POSIX.1
wordexp() function to generate the exact paths to the configuration files. The Windows
ExpandEnvironmentStrings() function seems reasonably similar, so you can wrap the differences around
#if defined(_WIN32) || defined(_WIN64) ... #else ... #endif. There is a Wiki on
predefined macros per operating system, if you need other OS-specific quirks.