简体   繁体   中英

My kbhit() is not Working On Mac, Making a PingPong Game

I am trying to build a ping-pong game on my mac using C++14 (g++ in terminal) and I am getting this error:

use of undeclared identifier 'kbhit'

here is the code: https://github.com/DemonJAZ/GamesC

The function is in GameManager , class named Input .

Since there is no sentence with a squiggly mark in the end, I took a liberty to invent a couple of my own.

Why am I getting this error?

There is no kbhit function in the C++ language.

Why am I seeing people using it all over the place? Why does it work for them?

They are using it on Windows. It's a Windows function. You are on Mac OS X.

I like to be able to use this function. What should I do?

There are several options.

  1. Develop on and for Windows,
  2. Find a port (ie a re-implementation in a different environment) of this function that works on Unix-based systems. I'm sure someone somewhere wrote one. Start with https://www.google.com/search?q=kbhit+mac and if this doesn't help, try https://www.google.com/search?q=kbhit+linux . In fact https://www.google.com/search?q=kbhit+ncurses will probably return the best results, but it's kinda hard to guess if you don't know exactly what to look for.
  3. When in Rome do as Romans do. Write to the widely used Unix terminal API known as curses (you probably want the ncurses version).

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM