https://github.com/brunexgeek/waitkey
Single-file portable implementation of 'waitKey' function
https://github.com/brunexgeek/waitkey
c99 gnu-linux interactive keyboard keypress single-file terminal windows xterm
Last synced: 3 months ago
JSON representation
Single-file portable implementation of 'waitKey' function
- Host: GitHub
- URL: https://github.com/brunexgeek/waitkey
- Owner: brunexgeek
- License: mit
- Created: 2018-10-10T03:43:43.000Z (over 6 years ago)
- Default Branch: master
- Last Pushed: 2023-08-16T15:08:55.000Z (almost 2 years ago)
- Last Synced: 2025-01-10T01:53:01.787Z (4 months ago)
- Topics: c99, gnu-linux, interactive, keyboard, keypress, single-file, terminal, windows, xterm
- Language: C
- Size: 18.6 KB
- Stars: 2
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# waitkey  
Single-file implementation of *waitKey* functionality compatible with GNU/Linux and Windows. No need for external dependencies.
The idea is to provide a function that waits for the user to press any key and return its code. The key pressed is not echoed on the screen.
```c
// adds the actual implementation with this inclusion
#define WK_IMPLEMENTATION
#include "waitkey.h"...
int input = WkWaitKey();
if (input == WKK_UP) {
printf("You pressed up arrow\n");
}
```The `WkWaitKey` function can detect every printable ASCII character and some special keys (e.g. arrows, insert, page down).
Other functions:
* `WkGetKeyName`: returns the name of a key (e.g. "WKK_A" for WKK_A).
* `WkGetTerminal`: returns the name of the current terminal (e.g. "xterm").
* `WkSetColor`: set the current foreground and/or background color.
* `WkResetColor`: set the foreground and background colors to its default.
* `WkGetScreenSize`: returns the amount of rows and columns in the screen.## Supported terminals
Currently this implementation can identify and work with the following terminals:
* xterm
* linux
* windowsBy default, *xterm* (GNU/Linux) or *windows* (Windows) is used if no terminal can be identified.
## How to use
Just copy `waitkey.h` to your project and include it wherever needed. You must set the macro `WK_IMPLEMENTATION` before one (and *only* one) of the inclusions to add the actual implementation (because everything is inside the header file).
## Why not use the library *XYZ*?
The main goal here is to provide a minimal *waitkey* functionality without depending on extra libraries and provide support for both GNU/Linux and Windows. If you need something more ~~fancy~~ complete, you probably should use *ncurses* or other stuff.
## License
All code in this repository is available under [MIT License](https://opensource.org/licenses/MIT).