Ctrl+Ins in Linux (NCurses)

Would someone with a PC-Linux box mind compiling this, running it, and pressing Ctrl+Ins and tell me what number you get?

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
#include <stdio.h>
#include <curses.h>

int main()
{
  int c;
  
  initscr();
  nonl();
  raw();
  noecho();
  set_escdelay( 50 );
  keypad( stdscr, TRUE );
  
  printw( "Press Esc to quit.\n" );
  refresh();
  
  do {
    c = getch();
    printw( "%d\n", c );
  } while (c != 27);
  
  endwin();
  return 0;
}


Don’t forget to link with -lcurses.
On an Ubuntu machine (physical machine, not a VM, and logging in at the machine [no shell, remote login, etc]) I get nothing.

Just for fun I also tried on bash for Windows where I get 331. If I use bash through ConEmu, however, I get 539.
program ends, 5~ is inputted

changing line 21:
27
91
50
59
53
126


on the tty, got 331
In terminator: nothing
tty1: 331
I wonder if it is a common Linux issue? I can't get it to register either, and I can't figure out what part of the system is eating it.

Thank you @Danny Toledo, 539 is the number I was looking for.

@ne555
May I ask what hardware/OS-combo you are using? If I understand you correctly, it looks like pressing Ctrl-Ins produced an escape sequence unrecognized by NCurses.
Last edited on
When I compile and run on my system (Mageia Linux) I get 542.

I believe that CTRL key combinations can be different depending on the values held in one of the header files (I don't remember which) and not all CTRL combinations are supported.

What is the value of MAX_KEY on your machine? And have you tried printing out the keyname() as well?




Ok, I’m going to trust Mageia Linux more than ConEmu (a fabulous Windows program)... but here’s the rub:

Ctrl+Key combinations are not enumerated by NCurses. People didn’t tend to use them back when NCurses was created.

So all the extended Ctrl+Key combinations are reported through NCurses as some large number in the 500’s.

Keys I am interested in:

  Ctrl+Ins (542)?   "kIC4"
  Ctrl+Del (522)    "kDC5"

  Ctrl+Home (538)   "kHOM5"
  Ctrl+End (533)   "kEND5"

  Ctrl+PgUp (558)   "kPRV5"
  Ctrl+PgDn (553)   "kNXT5"

  Ctrl+Up (569)   "kUP5"
  Ctrl+Down (528)   "kDN5"

  Ctrl+Left (548)   "kLFT5"
  Ctrl+Right (563)   "kRIT5"

I’m using Fedora with the standard XTerm-color256.


[edit]
@jlb
KEY_MAX = 511 (meaningless)
keyname(542) = "kIC4"

(All the other Ctrl+Key names produced end in "5", but as keyname(539) is "kHOM6" that has to be wrong...)
Last edited on
Heh, so I ran keyname() for everything in the 500 range:

500  (null) 501  (null) 502  (null) 503  (null) 504  (null) 505  (null) 506  (null) 507  (null) 508  (null) 509  (null)
510  (null) 511  (null) 512  (null) 513  (null) 514  (null) 515  (null) 516  (null) 517  (null) 518  (null) 519  (null)
520  kDC3   521  kDC4   522  kDC5   523  kDC6   524  kDC7   525  (null) 526  kDN3   527  kDN4   528  kDN5   529  kDN6
530  kDN7   531  kEND3  532  kEND4  533  kEND5  534  kEND6  535  kEND7  536  kHOM3  537  kHOM4  538  kHOM5  539  kHOM6
540  kHOM7  541  kIC3   542  kIC4   543  kIC5   544  kIC6   545  kIC7   546  kLFT3  547  kLFT4  548  kLFT5  549  kLFT6
550  kLFT7  551  kNXT3  552  kNXT4  553  kNXT5  554  kNXT6  555  kNXT7  556  kPRV3  557  kPRV4  558  kPRV5  559  kPRV6
560  kPRV7  561  kRIT3  562  kRIT4  563  kRIT5  564  kRIT6  565  kRIT7  566  (null) 567  kUP3   568  kUP4   569  kUP5
570  kUP6   571  kUP7   572  (null) 573  (null) 574  (null) 575  (null) 576  (null) 577  (null) 578  (null) 579  (null)
580  (null) 581  (null) 582  (null) 583  (null) 584  (null) 585  (null) 586  (null) 587  (null) 588  (null) 589  (null)
590  (null) 591  (null) 592  (null) 593  (null) 594  (null) 595  (null) 596  (null) 597  (null) 598  (null) 599  (null)

I know that ending-in-3 is Alt+Key, and ending-in-5 is Ctrl+Key, so I'm guessing I should be looking at 543 as "correct" -- on my system.

I'll be paying more attention to keyname()...

[edit] So, does anyone get numbers different than these?
Last edited on
Hah, sorry to keep spamming. Here's the trick:

man 3x keyname wrote:
The keyname function may return the names of user-defined string capa-
bilities which are defined in the terminfo entry via the -x option of
tic. This implementation automatically assigns at run-time keycodes to
user-defined strings which begin with "k". The keycodes start at
KEY_MAX, but are not guaranteed to be the same value for different runs
because user-defined codes are merged from all terminal descriptions
which have been loaded. The use_extended_names function controls
whether this data is loaded when the terminal description is read by
the library.
Emphasis mine

So, the keyname is important, but the actual key code may vary. LOL.
Ctrl+Key combinations are not enumerated by NCurses. People didn’t tend to use them back when NCurses was created.

When curses was first created many of the keys on current keyboards didn't even exist.

On my keyboard I get the following output:

CTRL-
INSERT 542 kIC5
DELETE 521 kDC5
HOME 537 kHOM5
END 532 kEND5
PGUP 557 kPRV5
PGDN 552 kNXT5

ALT-
INSER 540 kIC3
DELETE 519 kDC3
HOME 535 kHOM3
END 530 kEND3
PGUP 555 kPRV3
PGDN 550 kNXT3

So, does anyone get numbers different than these?

Here is what my system produces:

1
2
3
4
5
6
7
8
9
600     (null)  599     (null)  598     (null)  597     (null)  596     (null)  595     (null)  594     (null)  593     (null)  592     (null)  591     (null)
590     (null)  589     (null)  588     (null)  587     (null)  586     (null)  585     (null)  584     (null)  583     (null)  582     (null)  581     (null)
580     (null)  579     (null)  578     (null)  577     (null)  576     (null)  575     (null)  574     (null)  573     (null)  572     (null)  571     (null)
570     kUP7    569     kUP6    568     kUP5    567     kUP4    566     kUP3    565     (null)  564     kRIT7   563     kRIT6   562     kRIT5   561     kRIT4
560     kRIT3   559     kPRV7   558     kPRV6   557     kPRV5   556     kPRV4   555     kPRV3   554     kNXT7   553     kNXT6   552     kNXT5   551     kNXT4
550     kNXT3   549     kLFT7   548     kLFT6   547     kLFT5   546     kLFT4   545     kLFT3   544     kIC7    543     kIC6    542     kIC5    541     kIC4
540     kIC3    539     kHOM7   538     kHOM6   537     kHOM5   536     kHOM4   535     kHOM3   534     kEND7   533     kEND6   532     kEND5   531     kEND4
530     kEND3   529     kDN7    528     kDN6    527     kDN5    526     kDN4    525     kDN3    524     (null)  523     kDC7    522     kDC6    521     kDC5
520     kDC4    519     kDC3    518     (null)  517     (null)  516     (null)  515     (null)  514     (null)  513     (null)  512     (null)  511     (null)



Yeah, different.

WHAT I HAVE LEARNED: For keys > KEY_MAX, lookup the name using keyname().


Thank you all so much!
(You'll see what this is about shortly... LOL.)
Last edited on
Registered users can post here. Sign in or register to post.