1. keyboard input using getc(0)

Hi all, I am finding that after using an expression like "choice = getc(0)"
 the next time getc(0) is called, it doesn't wait for the keystroke. Something 
left in the keyboard buffer from the first call? 

 I did search the docs before posting, but couldn't find an answer. 

Thanks.

new topic     » topic index » view message » categorize

2. Re: keyboard input using getc(0)

Asa wrote:
> 
>  Hi all, I am finding that after using an expression like "choice = getc(0)"
>  the next time getc(0) is called, it doesn't wait for the keystroke. Something
> 
> left in the keyboard buffer from the first call? 
> 
>  I did search the docs before posting, but couldn't find an answer. 
> 
> Thanks.

Look up wait_key

Bernie

My files in archive:
WMOTOR, XMOTOR, W32ENGIN, MIXEDLIB, EU_ENGIN, WIN32ERU, WIN32API 

Can be downloaded here:
http://www.rapideuphoria.com/cgi-bin/asearch.exu?dos=on&win=on&lnx=on&gen=on&keywords=bernie+ryan

new topic     » goto parent     » topic index » view message » categorize

3. Re: keyboard input using getc(0)

Asa wrote:
> 
>  Hi all, I am finding that after using an expression like "choice = getc(0)"
>  the next time getc(0) is called, it doesn't wait for the keystroke. Something
> 
> left in the keyboard buffer from the first call? 
> 
>  I did search the docs before posting, but couldn't find an answer. 
> 

getc() will return multiple codes for special keys. wait_key will translate
those for you.

--
Jeremy Cowgar
http://jeremy.cowgar.com

new topic     » goto parent     » topic index » view message » categorize

4. Re: keyboard input using getc(0)

I have done that already, but would like to at least know what was 
up with getc(0)though. Before I switched to wait_key() i was doing this:

choice = getc(0)
choice = getc(0)

the first call would "clear the pipes" and the second, would work as expected :)

new topic     » goto parent     » topic index » view message » categorize

5. Re: keyboard input using getc(0)

Some keys cannot be expressed with only one ASCII code. For instance, F1 on
Linux is expressed as 3 ascii codes: 27, 79 and 80. So, using getc(0) would first
return 27. The very next call, 79 and again 80.

--
Jeremy Cowgar
http://jeremy.cowgar.com

new topic     » goto parent     » topic index » view message » categorize

6. Re: keyboard input using getc(0)

Asa wrote:
> 
>  Hi all, I am finding that after using an expression like "choice = getc(0)"
>  the next time getc(0) is called, it doesn't wait for the keystroke. Something
> 
> left in the keyboard buffer from the first call? 
> 
>  I did search the docs before posting, but couldn't find an answer. 
> 
> Thanks.

Hi

Run this after your getc

while get_key() != -1 do
end while
end procedure

or 

while getc() != -1 do
end while
end procedure

Chris

new topic     » goto parent     » topic index » view message » categorize

Search



Quick Links

User menu

Not signed in.

Misc Menu