[Lazarus] read single char from STDIN
Chris Kelling
kellingc at cox.net
Fri Nov 18 18:23:54 CET 2011
On Fri, Nov 18, 2011 at 11:48 AM, William Oliveira Ferreira wrote:
> i´ve always used
> c := ReadKey;
> ________________________________
> William de Oliveira Ferreira
> Bacharel em Sistemas de Informação
to expand on that, use the boolean function keypressed. Remember on IBM
compatibles that function keys send 2 scan codes. The first, #0, to
indicate a function key and not a normal key, and then the scan code for
the actual keypress. This includes the edit keys (insert, delete, home,
end, pgup, pgdn, and arrow keys).
Here is a code fragment for an example:
if keypressed then
begin
c := readkey;
if c = #0 then
begin
c := readkey;
case c of
#132 : doSomething;
.
.
.
end; {case c}
end {if #0 is true}
else
begin
case c of
#132 : doSomethingElse;
.
.
.
end; {case c}
end; {if #0 is false}
end; {if keypressed}
This is a Turbo Pascal convention (and FPC), not a standard or UCSD
Pascal convention. Remember that strings are not a standard type,
either.
>
>
> 2011/11/18 Henry Vermaak <henry.vermaak at gmail.com>
>
>> On 18/11/11 16:18, Chris Kirkpatrick wrote:
>>
>>> It really needs get(c) but this function, together with put(c),
>>> which
>>> were defined in Jensen & Wirth and all standard Pascals, has long
>>> been
>>> missing from Turbo Pascal, and all its deriviatives such as
>>> Freepascal.
>>>
>>
>> How does get(c) differ from read(c)? The problem here is with the
>> terminal buffering the characters until return is pressed, hence the
>> need
>> for re-configuring the terminal so that each key press is sent
>> immediately.
>>
>> Henry
>>
>>
>> --
>> ______________________________**_________________
>> Lazarus mailing list
>>
>> Lazarus at lists.lazarus.**freepascal.org<Lazarus at lists.lazarus.freepascal.org>
>>
>> http://lists.lazarus.**freepascal.org/mailman/**listinfo/lazarus<http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus>
>>
>
>
> ------------------------------
>
> --
> _______________________________________________
> Lazarus mailing list
> Lazarus at lists.lazarus.freepascal.org
> http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus
More information about the Lazarus
mailing list