Detected / read keystroke, cross-platform PHP CLI

I am trying to write a cross-platform PHP utility for personal use, rather than inventing anything. The code will work more or less

while (true) {
    $key = null;
    $key = check_key_pressed();
    if ($key) do_relevant_magic($key);
    usleep(250000);
}

I need something for check_key_pressed()which will return the value of the pressed key, without waiting EOF/EOL, without asking for input explicitly, until any key is pressed.

This one should work with * nix and windows , therefore ncursesit is not a parameter. I also do not need calls execfor external vbs or bash scripts, this should be done exclusively in PHP, I hope that I do not want too much.

EDIT . Of course, I tested other SO solutions, and none of them seem really cross-platform. Ncrursesand are readlinenot available in windows, and this should intercept keystrokes or keystrokes or input ready for both Linux and windows.

+4
source share

All Articles