Capture keypresses on Windows
Dieses Issue hat noch niemand übernommen.
- Vorherrschende Sprache
- C
- Sterne
- 40.4k
- Forks
- 8.1k
- Ø Merge
- 2 T. 13 Std.
- Gemergte PRs (30 T.)
- 96
Beschreibung
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.
Beitragsleitfaden
Erste Schritte
- Lies das ganze Issue und danach den Beitragsleitfaden des Projekts.
- Schreib ins Issue, dass du es übernimmst — das erspart doppelte Arbeit.
- Forke das Repository und arbeite in einem Branch.
- Öffne einen Pull Request, der die Issue-Nummer nennt.
Rechercherichtung
Beginne mit der Durchsicht der historischen Diskussion unter bugs.php.net/bug.php?id=34972 und der bestehenden Verarbeitung von Terminaleingaben in php-src. Ermittle den geeigneten Windows-Einstiegspunkt und wie das Erfassen einzelner Tastendrücke auf den unterstützten Betriebssystemen funktionieren soll. Als abgeschlossen gilt die Aufgabe, wenn eine dokumentierte, getestete plattformübergreifende Möglichkeit vorhanden ist, eine Taste zu lesen, ohne Enter zu benötigen.
Vom Indexierungsmodell aus dem Issue-Text verfasst.
Bewertung
- Tech-Stack
- c, php
- Bereich
- cli, operating-systems
- Issue-Typ
- Feature
- Schwierigkeit
- 5/5
- Geschätzter Aufwand
- Über eine Woche
- Aktivitätsstatus
- Veraltet
- Klarheit
- Größtenteils klar
- Anfängerfreundlichkeit
- 35/100