Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- * 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 <http://www.gnu.org/licenses/>.
- */
- // 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 <stdio.h>
- #include <curses.h>
- 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
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement