I have this program in C
that reads the input like this:
cod1 = getch ();
if (kbhit())
cod2 = getch ();
I can read every Ctrl+Char possible sequences, except for Ctrl+C, that closes the program - that is OK, and Ctrl+S, that simple is not catch. But I wanted to make Ctrl+S to be the save function in my program; how could I do that? Furthermore, is it possible to read Alt+Char characters? Because it reads it as a regular character, e.g., Alt+A is read with the same codes as A.
Your problem is that input probably gets eaten by terminal emulator.
For example Alt+<Whatever>
is often reserved for menu shortcuts (e.g. Alt+F
opens File
menu). Matching characters are often hilighted once you hold Alt
(F
get's underscored in File
).
Ctrl+S
is reserved for Stops all output on screen (XOFF)
(again your terminal emulator does that).
As for using Alt+<...>
as shortcuts in your command line application. As far as I'm concerned holding Alt
doesn't affect character received, it just sets flags which are hard to access in console. Even in GUI application (in Windows) it's quite tricky and you have to use function like GetAsyncState()
to check whether alt was pressed.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With