Inkey$ function

Discuss any general programming issues here
Post Reply
amigaoneproductions
Posts: 32
Joined: Mon Feb 15, 2010 4:14 pm
Location: Nottinghamshire, UK
Contact:

Inkey$ function

Post 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 ?
User avatar
Allanon
Posts: 732
Joined: Sun Feb 14, 2010 7:53 pm
Location: Italy
Contact:

Re: Inkey$ function

Post 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 ;)
amigaoneproductions
Posts: 32
Joined: Mon Feb 15, 2010 4:14 pm
Location: Nottinghamshire, UK
Contact:

Re: Inkey$ function

Post by amigaoneproductions »

Thanks, that looks very useful, looks a lot better way of doing things :)
Post Reply