Guest User

Untitled

a guest
Jan 21st, 2018
85
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.04 KB | None | 0 0
  1. #include <stdlib.h>
  2. #include <ncursesw/ncurses.h>
  3.  
  4. /* gcc -o keytest -I/opt/local/include -lncurses keytest.c */
  5. /* TERM=xterm ./keytest
  6. Try Control-left, Sh-F9, Control-UP, etc
  7. * */
  8.  
  9. static struct key {
  10. char *name;
  11. int code;
  12. } Keys[] = {
  13. { "kLFT5", 0 },
  14. { "kEND5", 0 },
  15. { "kHOM5", 0 },
  16. { "kHOM3", 0 },
  17. { "kUP5", 0 },
  18. { "kDN5", 0 },
  19. { 0, 0 }
  20. };
  21.  
  22. int main(void)
  23. {
  24. int i;
  25. use_extended_names(TRUE);
  26. initscr();
  27. cbreak();
  28. noecho();
  29. nonl();
  30. keypad(stdscr,TRUE);
  31.  
  32. for (i = 0; Keys[i].name != 0; ++i) {
  33. int code;
  34. char *s = tigetstr(Keys[i].name);
  35. if (s && (long)(s) != -1) {
  36. printw("tigetstr for %s=%s\n", Keys[i].name, s);
  37. code = key_defined(s);
  38. if (code > 0) {
  39. Keys[i].code = code;
  40. }
  41. }
  42. }
  43. addstr("press a key");
  44. int ch = getch();
  45. int ch1 = getch();
  46. int ch2 = getch();
  47. int ch3 = getch();
  48. endwin();
  49. printf("keypress=%d\n", ch);
  50. printf("keypress=%d\n", ch1);
  51. printf("keypress=%d\n", ch2);
  52. printf("keypress=%d\n", ch3);
  53. for (i=0;Keys[i].name;++i) {
  54. printf("key=%s, code=%d\n", Keys[i].name, Keys[i].code);
  55. }
  56. exit(0);
  57. }
Add Comment
Please, Sign In to add comment