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 » Wed Mar 03, 2010 8:56 pm

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: 442
Joined: Sun Feb 14, 2010 7:53 pm
Location: Italy
Contact:

Re: Inkey$ function

Post by Allanon » Wed Mar 03, 2010 10:11 pm

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 ;)
----------------------------
[Allanon] Fabio Falcucci
AMC - Creative Development // Docs Site // Support Forum
Support me on Patreon for Hollywood libraries!

amigaoneproductions
Posts: 32
Joined: Mon Feb 15, 2010 4:14 pm
Location: Nottinghamshire, UK
Contact:

Re: Inkey$ function

Post by amigaoneproductions » Thu Mar 04, 2010 11:28 pm

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

Post Reply