Input클래스

jh Seo·2023년 7월 24일
0

Input.h

#ifndef _Input_H
#define _Input_H
#include <ncurses.h>

char getInput()
{
    int input = getch();
    char retCh;
    switch (input)
    {
    case KEY_UP:
        retCh= 'U';    
        break;
    case KEY_LEFT:
        retCh= 'L';    

        break;
    case KEY_RIGHT:
        retCh= 'R';    

        break;
    case KEY_DOWN:
        retCh= 'D';    

        break;
    default:
        retCh='X';
       break;
    }
    return retCh;
}
#endif

Main에서 호출하는 getInput함수이다.

주의할점은 getch함수는 입력값이 있을때까지 blocking이 되는 함수이다.
따라서 메인에서

nodelay(stdscr,TRUE);   

함수를 실행해야 non-blocking으로 작동해서 프로그램이 멈추지않는다.

profile
코딩 창고!

2개의 댓글

comment-user-thumbnail
2023년 7월 24일

많은 도움이 되었습니다, 감사합니다.

답글 달기

nodelay를 main 함수 내부에 작성하는 건가요? 그렇다면 어느 위치에 넣어야 할까요? 알려주시면 감사하겠습니다ㅠㅠ

답글 달기