Open
Description
Description
Some tutorials and packages show it is possible to capture and handle keypresses on terminals, but only available on *nix systems
The example below shows a commonly see implementation.
<?php
$stdin = fopen('php://stdin', 'r');
system('stty cbreak -echo');
stream_set_blocking($stdin, false);
while (1) {
$keypress = fgets($stdin);
if ($keypress) {
echo 'Key pressed: ' . $keypress . PHP_EOL;
}
}
EDIT:
This example captures keys presses in the open terminal, except: shift, alt, control, caps lock, meta and fn
This example above does not work on Windows.
The intention is to capture a single keypress, of course, without typing enter. This would make possible things like terminal games and many command line apps, working for any O.S.
This was discussed in the past here: https://bugs.php.net/bug.php?id=34972
CMB gave some hope this would be implemented, and so, not a bug at all.