Tyler Durden
Tyler Durden

Reputation: 11558

Capture Ctrl-Enter in raw mode with getchar()?

Is there any way to capture the key combination Ctrl-Enter when processing keystrokes with getchar() after setting the terminal to raw mode?

When test it, I just get the char value 10 which is the same whether Ctrl is held down or not.

Upvotes: 0

Views: 379

Answers (1)

Tyler Durden
Tyler Durden

Reputation: 11558

After doing some more experimentation, it appears that most terminals do not send a unique keysym for Ctrl-Enter. By using a getchar loop you can see the full keysym codes for any terminal keypress:

// set terminal to raw, then...
while( int c = getchar() ) printf( "%d ", c );

Some keys like F1 and Ctrl-K will generate codes, but other key combinations will not. Ctrl-Enter unfortunately is not an encodable key combination. Of course, using signals with root access it can be detected from a local console, but not from a terminal.

Upvotes: 2

Related Questions