[Gambas-user] functional equivalent to inkey$ in gb.ncurses?

Tobias Boege taboege at gmail.com
Wed Nov 14 20:25:31 CET 2018


On Wed, 14 Nov 2018, T Lee Davidson wrote:
> On 11/14/18 1:33 PM, KKing wrote:
> > In some old code I have roughly below, which I'd like to replicate in gb.ncurses but the Window.Read waits until a there is a
> > keystroke, is there an alternative?
> > 
> > <<
> > Label1:
> >     v$ = inkey$
> >     IF v$ = "" THEN
> >         ' code to update an on screen clock and short a heartbeat
> >     ELSE
> >         ' code to deal with the input character
> >     END IF
> >     GOTO Label1
> >>>
> 
> Perhaps the Window Read event would serve your purpose.

Yes, that would be better. Gambas supports event-driven programming and
gb.ncurses tries to give you that to a degree. You can have a Window_Read
event handler to deal with input and a Timer to redraw a clock and let
the event loop handle dispatching of your code.

Alternatively, the Window.Read() method has a TimeOut parameter.
If I saw correctly what this "inkey$" is supposed to do (you didn't
tell), namely not block and return an empty string if the input queue
is empty, then set that TimeOut to zero.

But beware that Window.Read returns a keycode Integer, not a string.
If returned integer will be zero if the timeout expired without something
arriving in the input queue. This is different from returning an empty
string, as inkey$ would do.

Regards,
Tobi

-- 
"There's an old saying: Don't change anything... ever!" -- Mr. Monk


More information about the User mailing list