You are here: Re: How to get a keypress? « PHP Programming Language « IT news, forums, messages
Re: How to get a keypress?

Posted by Lars Eighner on 09/15/07 05:06

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 ";
}
}

}
?>


--
Lars Eighner <http://larseighner.com/> <http://myspace.com/larseighner>
Countdown: 493 days to go.
What do you do when you're debranded?

 

Navigation:

[Reply to this message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация