Monday, May 21, 2007

Inkey$ and Liberty BASIC

There has been some discussion in the support forum about extending keyboard handling in Liberty BASIC programs. Currently we only allow doing something like this in the graphics views. Two things (maybe more?) are missing:
  • Getting the next character in the mainwindow without stopping the program. Currently only INPUT and INPUT$() are supported. Both stop the program and wait.
  • Getting the next character typed for some window or widget that has focus. In other words, reading keypresses for objects with handles (ie. #thisWindow)

What I suggested in the forum is a function called inkey$().

The following would read keypresses for the mainwindow:

print inkey$()

or it could be abbreviated to:

print inkey$

To read keypresses for windows or widgets with handles:

print inkey$(#handle)

I'd like to solicit feedback here. Any ideas? Please leave a comment, and thanks!

6 comments:

Jerry Muelver said...

I would like to see inkey$() trap, rather than watch, keystrokes. Then you could have

while inkey$() <> chr$(13)
'grab keystrokes and process them
end while

Unknown said...

As proposed, that's great! The only thing I'd suggest is a keyboard event handler for windows, like trapclose or resizehandler.

Carl Gundel said...

Jerry,

I do understand the need for a key trap, but naming it inkey$ would be confusing for people I think.

benjamin805 said...

I would like to be able to read the input from say a text box and if they press Enter, this cause an update to an array or a data file. This can be done right now using a loop with scan in it, but a single line text box will not cause the loop to react when Enter or Tab is pressed.

Unknown said...

It has pained me not having inkey$ available in LB on the text screen. I am accustomed to using this function in many different situations (typically the "Hit Any Key" option). I do hope you add it to the text commands.

Anonymous said...

I have friends who use the mainwin for quick and dirty progs. They use the GETASYNC function to read the keyboard. If Inkey$() would exist than they would never be pushed to use the IDE (and GUI programming)
Just a thought.

Gordon