|
Posted by Norman Peelman on 09/15/07 11:35
Lars Eighner wrote:
> In our last episode, <46eb63bb$0$28796$4c368faf@roadrunner.com>, the lovely
> and talented Norman Peelman broadcast on comp.lang.php:
>
>> Jim Carlock wrote:
>>> Lars Eighner asked...
>>>> How can I get keypresses?
>>> "Norman Peelman" replied...
>>> : If you're on Windows, you can't.
>>>
>>> HTML provides a way to get a keypress. Usually this can be
>>> done with javascript or HTML inside the <head> section or
>>> HTML inside the body. I've not messed with it, but have seen
>>> it in other folks code.
>>>
>>> If he just wants a way to provide client-side control, it's
>>> called accesskey in HTML-speak.
>>>
>>> http://www.w3.org/TR/html4/interact/forms.html#h-17.11.2
>>>
>>> That combined with some javascript to do an automatic POST,
>>> probably can get the OP where he wants to go.
>>>
>
>> The OP is in a terminal (cli) window... no browser.
>
> And no HTML, Javascript. There is simply no difficulty in doing this
> with served PHP browsed with, say, lynx --- and for that matter doing it
> without a server using lynxexec. I'm talking about doing this directly
> with a terminal without server/browser overhead and without the both
> of POST etc.
>
> And I was wrong that fread will do it. I'm still looking for a way to
> get key presses without having to hit return and without their echoing
> to the terminal.
>
> Look, the following will make a perfectly acceptable box in a (fullscreen)
> window. The problem is what to write for the commented line that will
> give me the value of the key pressed and not mess up the pretty screen.
>
> #!/usr/local/bin/php
>
> <?php
> print "\x1b[2J\x1b[=3A";
> window(0,0,80,25,7);
> border(10,10,70,20,4);
>
> // See if UpArrow is pressed:
> // ??? $keypress = fread(STDIN,1); DOESN'T WORK
> // if ($keypress = "\x1b[A"){ print "yes";}
>
>
> function window($minx,$miny,$maxx,$maxy,$bgc){
> for ($i = $minx; $i < $maxx + 1; $i++){
> for ($j = $miny; $j < $maxy +1; $j++){
> print "\x1b[$j;{$i}f";
> print "\x1b[1;4{$bgc}m ";
> }
> }
> function border($minx,$miny,$maxx,$maxy,$bgc){
> $j=$miny;
> for ($i = $minx; $i < $maxx + 1; $i++){
> print "\x1b[$j;{$i}f";
> print "\x1b[1;4{$bgc}m ";
> }
> $j=$maxy;
> for ($i = $minx; $i < $maxx + 1; $i++){
> print "\x1b[$j;{$i}f";
> print "\x1b[1;4{$bgc}m ";
> }
> $i=$minx;
> for ($j = $miny + 1; $j < $maxy; $j++){
> print "\x1b[$j;{$i}f";
> print "\x1b[1;4{$bgc}m ";
> }
> $i=$maxx;
> for ($j = $miny + 1; $j < $maxy; $j++){
> print "\x1b[$j;{$i}f";
> print "\x1b[1;4{$bgc}m ";
> }
> }
>
> }
> ?>
>
>
Take a look here:
http://us.php.net/manual/en/function.fgetc.php
http://us2.php.net/manual/en/wrappers.php.php
There is an example in the first link that I think will help you.
Norm
Navigation:
[Reply to this message]
|