You can now directly inquire the terminal of its termcap entries using control sequences, “XTGETTCAP”, full for ~23% of terminals, or just keyboard caps from ~15%, probably too little too late, but it is possible to directly ask a terminal and I think it is the correct solution.