/* * This file is part of the FBK C code Examples distribution (https://filmsbyrkis.com). * Copyright (c) 2022 Kris Occhipinti. * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, version 3. * * This program is distributed in the hope that it will be useful, but * WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ // This displays keys being pressed // WASD will show UP, LEFT, DOWN, RIGHT //Dependencies: // sudo apt-get install libncurses5-dev libncursesw5-dev //Compile: // gcc main.c -o main -W -Wall -Werror -Wextra -lncurses #include #include void get_char(); int main(void) { get_char(); return 0; } void get_char() { while (1){ initscr(); // mandatory curses init cbreak(); // unbuffered input int chr; do { chr = getch(); clear(); } while (chr == ERR); if(chr == 97){ printw("LEFT\n"); } else if(chr == 100){ printw("RIGHT\n"); } else if(chr == 115){ printw("DOWN\n"); } else if(chr == 119){ printw("UP\n"); } else { printw("chr = %i\n", chr); } refresh(); // show the printf stuff } endwin(); // curses cleanup }