1

I am working on a CHIP-8 emulator to be used on a Linux system. As I understand it, I need to get keyboard input from (any) 16 keys and map these to a hex keypad. Once I get the inputs, I have no trouble mapping them to the 16 CHIP-8 keys.

However, I cannot figure out how to actually tell if a key is pressed. I believe in Java I would use keylistener, but I cannot find anything analogous for Linux in C++. Is there a way I can tell what (if any) specific keys are pressed at any given time? Something like a getKeyState function I could call?

Thanks in advance.

Kevin Rogers
  • 75
  • 1
  • 8
  • Is this a GUI or Command-line application? In commandline, you'd use `tcsetattr` and set a timeout which allows you to use a `read` style function to check if there is input - or use a library such as `ncurses` which has functions to "check if a key has been pressed". – Mats Petersson Apr 03 '14 at 22:20

2 Answers2

0

Your program may read the characters from standard input.

You can use fgets() library function to perform the reading.

See, for example:

Community
  • 1
  • 1
Arun
  • 19,002
  • 9
  • 48
  • 59
  • That's not particularly useful if you actually want to also do other things, and pretend that keypresses are for example interrupts or polled events in some "hardware" in the chip emulator. – Mats Petersson Apr 03 '14 at 22:35
0

There is this tutorial on ncurses. NCURSES Programming HOWTO. I have confirmed that on my MacBook Pro, Mavericks 10.9.1, with the Xcode Command Line Tools installation, that the ncurses.h is a symbolic link to curses.h, both located in /usr/include. This is the NCURSES Introduction page.

I have not created a specific class myself. However, some searching on /dev/input/eventX, where X seems to be either a zero or one finds these two separate posts:Read from /dev/input and linux keypress events.

Community
  • 1
  • 1