Home
JAQForum Ver 24.01
Log In or Join  
Active Topics
Local Time 07:30 16 Jun 2026 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 : Help with Picomite INKEY$ Function

Author Message
apalert
Regular Member

Joined: 06/07/2023
Location: Australia
Posts: 47
Posted: 01:06pm 11 Jun 2026
Copy link to clipboard 
Print this post

Looking to wait for Up or Down arrow to be pressed. Just to test the idea I've been inputting this and similar at the command prompt but doesn't work as hoped!

x=1 : do : loop while inkey$="" : if inkey$ = chr$(128) then x = x+1  : Print x
 
matherp
Guru

Joined: 11/12/2012
Location: United Kingdom
Posts: 11479
Posted: 01:17pm 11 Jun 2026
Copy link to clipboard 
Print this post

inkey$ consumes the keypress so you can't read it again
Do
x=1
s$=Inkey$
Loop While s$=""
If s$=Chr$(128) Then x=x+1:Print x
 
phil99

Guru

Joined: 11/02/2018
Location: Australia
Posts: 3285
Posted: 01:22pm 11 Jun 2026
Copy link to clipboard 
Print this post

To make it work on one line:-
> x=1 : do : loop until inkey$ = chr$(128) : inc x : Print x
2
>
 
apalert
Regular Member

Joined: 06/07/2023
Location: Australia
Posts: 47
Posted: 08:52pm 11 Jun 2026
Copy link to clipboard 
Print this post

Thanks Peter as always!

Thanks Phil, you've woken me up to using the INC function as well! I figured you can get a decrement using INC variable, -1. Oh boy, when I think of the copious variable = variable + 1 and variable = variable - 1 in my code. Not only does INC look slick, the manual says it processes much faster.

I actually want bigger steps than 1 so I've ended up, as a demo for using both Up and Down keys, with:

dim float x
dim string s$

x=10
do
Do
 s$=Inkey$
 Loop While s$=""
If s$=Chr$(128) Then inc x,10:Print x
If s$=Chr$(129) Then inc x,-10:Print x
loop
 
PhenixRising
Guru

Joined: 07/11/2023
Location: United Kingdom
Posts: 1944
Posted: 07:59am 15 Jun 2026
Copy link to clipboard 
Print this post

  apalert said   Not only does INC look slick, the manual says it processes much faster.


Please verify this. It definitely was true but when I tested with Tracecache, the old method was faster.
 
phil99

Guru

Joined: 11/02/2018
Location: Australia
Posts: 3285
Posted: 08:39am 15 Jun 2026
Copy link to clipboard 
Print this post

> Clear :dim integer n, m
> t=timer:for m=0 to 999999: inc n :next:? timer-t,n,m
3148.165        1000000         1000000
> Clear :dim integer n, m
> t=timer:for m=0 to 999999: n=n+1 :next:? timer-t,n,m
5609.588        1000000         1000000
> option list
PicoMiteVGA MMBasic RP2350A Edition V6.03.00RC15
OPTION RESOLUTION 800x600 @ 360000KHz

For comparison the same loop doing nothing.
> Clear :dim integer n, m
> t=timer:for m=0 to 999999:       :next:? timer-t,n,m
1227.124        0       1000000
>

Edited 2026-06-15 18:50 by phil99
 
toml_12953
Guru

Joined: 13/02/2015
Location: United States
Posts: 652
Posted: 11:03am 15 Jun 2026
Copy link to clipboard 
Print this post

  PhenixRising said  
  apalert said   Not only does INC look slick, the manual says it processes much faster.


Please verify this. It definitely was true but when I tested with Tracecache, the old method was faster.


In the following program, replacing statements in the DO LOOP with INC
shaved a few tenths of a second off the time thereby raising the Index:

TIMER =0
CONST loops%=9865
DIM float x, r0
DIM integer i
FOR i=1 TO loops
 r0=10
 DO
   x=r0
   INC x
   INC x,-4.567e-4
   INC x,70
   INC x,-69
   x=x*7
   x=x/11
   INC r0,-1
 LOOP WHILE r0>0
 x=LOG(x)
 x=SIN(x)
 x=SQR(x)
 x=SQR(x)
NEXT i
PRINT x
t=TIMER/1000
PRINT "Loops:";loops
PRINT "Time:";t;" seconds"
PRINT "Index:";34/t*loops
 
Print this page


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

The Back Shed's forum code is written, and hosted, in Australia.
© JAQ Software 2026