Page 1 of 1

Inkey$ function

Posted: Wed Mar 03, 2010 8:56 pm
by amigaoneproductions
Is there any function that will return a buffered input from the keyboard in the same way that the BASIC function Inkey$ would do ?

I have two problems with using InKeyStr()

1. It echos to the screen the characters being input
2. It needs a RETURN or ENTER key to end the input (so you can't have any other processes going on while waiting for an input, your code is effectively halted.

Writing a tight loop to test for keypresses with IsKeyDown() is not very effective, uses a lot of processor time, and if you type quickly, it misses keypresses.

Any ideas ?

Re: Inkey$ function

Posted: Wed Mar 03, 2010 10:11 pm
by Allanon
Why not using an event to monitor keypresses?

Code: Select all

Function check_key(msg)
   Print("Key pressed:", msg.key)
EndFunction

installEventHandler( { OnKeyDown = check_key } )

Repeat
   WaitEvent()
Forever
This should resolve your problem ;)

Re: Inkey$ function

Posted: Thu Mar 04, 2010 11:28 pm
by amigaoneproductions
Thanks, that looks very useful, looks a lot better way of doing things :)