tevent.pp 843 B

123456789101112131415161718192021222324252627282930313233343536373839
  1. program test_event;
  2. {$MODE OBJFPC}
  3. uses
  4. ncurses, sysutils;
  5. var
  6. ch: chtype;
  7. begin
  8. try
  9. initscr();
  10. noecho();
  11. clear();
  12. cbreak();
  13. keypad(stdscr, TRUE);
  14. mousemask(1, nil);
  15. mvaddstr(1, 1,'press F10 or q to exit');
  16. mvaddstr(2, 1,'press 1 to cbreak mode');
  17. mvaddstr(3, 1,'press 2 to raw mode');
  18. mvaddstr(4, 1,'press 3 to halfdelay(10) mode');
  19. repeat
  20. ch := getch;
  21. mvaddstr(LINES - 1, 1,' ');
  22. case ch of
  23. ERR: mvaddstr(LINES - 1, 1,'timeout: 1 sec');
  24. chtype('1'): cbreak();
  25. chtype('2'): raw();
  26. chtype('3'): halfdelay(10);
  27. else
  28. mvaddstr(LINES - 1, 1,PChar(Format('name:%-14s code:%d', [ keyname(ch), ch ] )));
  29. end;
  30. until (ch = chtype('q')) OR (ch = KEY_F(10));
  31. finally
  32. endwin();
  33. end;
  34. end.