[php-src] Issue #12939: Capture keypresses on Windows
| From: | terremoth | Date: | Tue, 12 Dec 2023 02:40:08 +0000 |
| Subject: | [php-src] Issue #12939: Capture keypresses on Windows | ||
| Groups: | php.bugs | ||
| Request: | Send a blank email to php-bugs+get-246040@lists.php.net to get a copy of this message | ||
Issue: https://github.com/php/php-src/issues/12939
Author: terremoth
### 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
<?php
$stdin = fopen('php://stdin', 'r');
stream_set_blocking($stdin, 0);
while (1) {
$keypress = fgets($stdin);
if ($keypress) {
echo 'Key pressed: ' . $keypress . PHP_EOL;
}
}
```
But that 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.