0

I am trying to create a version of pong for the MacOS terminal. However, I cannot seem to get single key input (my version of saying detecting which key is pressed at certain times.). I have tried everything, (even using the getch() function used in the depreciated library conio.h. I am looking to use it in a function like this:

void detect_w()
{
    int ascii_key_pressed_code = <some function to get pressed keys>;
    if (ascii_key_pressed_code == 0xa9)
    {
        // the ascii code for "A" triggered.
        // do something...
    }
    // ....
}

For anyone who thinks "just use cin", I want unbuffered input.

  • What problem are you having with `getch`? – Alan Birtles May 07 '20 at 07:51
  • as I said in the question, `getch()` is depreciated. The gcc compiler complains about `conio.h` - a DOS library, not existing. –  May 07 '20 at 07:54
  • conio.h is DOS/Windows only. You are looking for curses or ncurses. – Thomas Sablik May 07 '20 at 07:55
  • `getch` isn't deprecated you just need to include the correct headers for your platform: https://developer.apple.com/library/archive/documentation/System/Conceptual/ManPages_iPhoneOS/man3/getch.3x.html – Alan Birtles May 07 '20 at 08:01
  • That is incorrect. On linux, you cannot include `conio.h`, making it impossible to use. –  May 07 '20 at 08:10
  • also, my mac is from 2006 so I am kind of stuck on OSX lion. This means that I cannot use brew, yum or any other package managers to install extra G++ or GCC headers. –  May 07 '20 at 08:11
  • type `man getch` into your terminal – Alan Birtles May 07 '20 at 08:30
  • `getch()` isn't what I am looking for - I don't want the entire terminal to pause. I just want to be able to see what keys are pressed at one time. –  May 07 '20 at 08:35
  • https://stackoverflow.com/questions/29537616/ncurses-background-waiting-for-exit – Alan Birtles May 07 '20 at 08:52

0 Answers0