~riderius/cpp-code

11395c93e77d6608146c91d960ecd0a14eb5e2a6 — RIDERIUS 6 months ago b813946
Added ncurses prog: keylog

Signed-off-by: RIDERIUS <riderius.help@gmail.com>
2 files changed, 22 insertions(+), 0 deletions(-)

M CMakeLists.txt
A keylog.cpp
M CMakeLists.txt => CMakeLists.txt +2 -0
@@ 27,7 27,9 @@ find_package(Curses)
if(CURSES_FOUND)
    include_directories(${CURSES_INCLUDE_DIRS})
    add_executable(screensaver screensaver.cpp)
    add_executable(keylog keylog.cpp)
    target_link_libraries(screensaver ${CURSES_LIBRARY})
    target_link_libraries(keylog ${CURSES_LIBRARY})
else()
    message(WARNING "Failed to find ncursesw. Curses programs do not compile.")
endif()

A keylog.cpp => keylog.cpp +20 -0
@@ 0,0 1,20 @@
#include <locale>
#include <ncurses.h>

int main(void) {
  setlocale(LC_ALL, "");
  initscr();
  clear();
  noecho();

  printw("Enter a symbol\nExit: ESC");
  refresh();
  char ch;
  WINDOW *win = newwin(LINES / 2 - 1, COLS / 2 - 4, LINES / 2 - 1, COLS / 2 - 4);
  while ((ch = wgetch(win)) != 27) {
    wclear(win);
    wprintw(win, "%s = %d", keyname(ch), ch);
  }
  endwin();
  return 0;
}