Home
JAQForum Ver 24.01
Log In or Join  
Active Topics
Local Time 12:40 25 Nov 2024 Privacy Policy
Jump to

Notice. New forum software under development. It's going to miss a few functions and look a bit ugly for a while, but I'm working on it full time now as the old forum was too unstable. Couple days, all good. If you notice any issues, please contact me.

Forum Index : Microcontroller and PC projects : MM Basic - INKEY$

Author Message
BobD

Guru

Joined: 07/12/2011
Location: Australia
Posts: 935
Posted: 10:34pm 23 Feb 2012
Copy link to clipboard 
Print this post

When I build a menu I like to use a single keystroke entry without the need for a <CR>. In my thinking it leads to a clean UI. So I have been using INKEY$ as the means of getting the keystrokes. While doing that I ran across some difficulties. The following code does not work. All I get is the loop exits but I get null values presented.
? " Tell me what to do"
do
loop until inkey$ <> ""
k=val(inkey$)
on k gosub dummy, dummy, dummy, dummy, dummy, dummy, dummy, dummy, dummy


After some experimentation I have this code which works.
? " Tell me what to do > ";
Do
k$=Inkey$
Loop Until k$ <> ""
k=Val(k$)
On k GoSub dummy, dummy, dummy, dummy, dummy, dummy, dummy, dummy, dummy


Ignore the "gosub dummy". I build my front end first and then as I finish the work modules I then include access to them, in this case via the "on k gosub". Until it is all finished I have a subroutine named Dummy: which does nothing but return.

My conclusion is that INKEY$ only has a valid value until the first access after it is set and if you want to continue use of that value then it has to be saved as in "k=val(inkey$)". Is this correct?

Are there any other variables that may work similar? MM.I2C may be another one but I haven't tried it.
 
bigmik

Guru

Joined: 20/06/2011
Location: Australia
Posts: 2914
Posted: 10:39pm 23 Feb 2012
Copy link to clipboard 
Print this post

  BobD said  

My conclusion is that INKEY$ only has a valid value until the first access after it is set and if you want to continue use of that value then it has to be saved as in "k=val(inkey$)". Is this correct?



Hi Bob,

I think your synapses is correct. You are basically doing TWO Inkey$ tests the first one exits your loop and the second one returns a NULL so doesnt work.

It is standard practise to assign a variable to the Inkey$ read and then test it as you have done in your second example.

Regards,

Mick

Mick's uMite Stuff can be found >>> HERE (Kindly hosted by Dontronics) <<<
 
djuqa

Guru

Joined: 23/11/2011
Location: Australia
Posts: 447
Posted: 11:44pm 23 Feb 2012
Copy link to clipboard 
Print this post

Inkey$ is a Pseudo-variable.
It obtains the current keypress value each time it is used.
Therefore as BIGMIK stated you need to assign the value to a variable to allow you to use it in the manner you wish.


VK4MU MicroController Units

 
Print this page


To reply to this topic, you need to log in.

© JAQ Software 2024