Forum
Using inkey - Printable Version

+- Forum (https://www.boriel.com/forum)
+-- Forum: Compilers and Computer Languages (https://www.boriel.com/forum/forumdisplay.php?fid=12)
+--- Forum: ZX Basic Compiler (https://www.boriel.com/forum/forumdisplay.php?fid=11)
+---- Forum: Help & Support (https://www.boriel.com/forum/forumdisplay.php?fid=16)
+---- Thread: Using inkey (/showthread.php?tid=639)



Using inkey - ardentcrest - 01-20-2015

Any one know how to do something like this

I'm looking to use inkey$ to create a line of text while the program is doing some other things Ie

LOOP
DO THING 1
INKEY(text string)
DO THING 2
IF ENTER PRINT(text String)
GOTO LOOP

any help on this


Re: Using inkey - boriel - 01-20-2015

ardentcrest Wrote:Any one know how to do something like this

I'm looking to use inkey$ to create a line of text while the program is doing some other things Ie

LOOP
DO THING 1
INKEY(text string)
DO THING 2
IF ENTER PRINT(text String)
GOTO LOOP

any help on this

Yes, use the IN (read port) which does not interrupt.
There is a library already for this.

Code:
#include <keys.bas>
if MultiKeys(KEYENTER) then
   PRINT "Enter pressed"
end if
Multikeys uses KEYxxxx constants (see this source at the end for available constants) and can check for several keys at once, using bOR or | (bitwise OR):
Code:
#include <keys.bas>
if MultiKeys(KEYO | KEYZ) then
   PRINT "Key O, Key Z or both pressed"  ' letter case does not matter!
end if



Re: Using inkey - ardentcrest - 01-20-2015

This could be of help. for other parts of my program

But I dont think its what I'm looking for.

I want to type in a line of text while other things are happening.


Re: Using inkey - boriel - 01-20-2015

Have a look at INPUT.BAS code (a library to simulate INPUT)

ardentcrest Wrote:This could be of help. for other parts of my program
But I dont think its what I'm looking for.

I want to type in a line of text while other things are happening.
Then you might want to store the value of INKEY$. INKEY does not lock your program execution:
Code:
myLine = ""
row = 0

LOOP1:
  DO_THING 1
  K$ = INKEY$
  IF K$ = CHR$(13) THEN ' Enter
    LET row = row + 1
    myLine = ""
  END IF
PRINT AT row, 0; MyLine$;: REM add ; "_"; to have a cursor
GOTO LOOP1



Re: Using inkey - ardentcrest - 01-20-2015

ty


Re: Using inkey - ardentcrest - 01-20-2015

PS

Hope everything is working out all right for you Boriel.


Re: Using inkey - boriel - 01-20-2015

ardentcrest Wrote:PS

Hope everything is working out all right for you Boriel.
Thanks! I will tell you later privately ;-)


Re: Using inkey - ardentcrest - 02-19-2015

HUMMMMM. Posts when missing Sad

Need help. This compiles with no errors but still will not work. Any help.

Code:
10 dim z$ : let z$="this is a test of an inkey$ editor                 " : gosub 2000 :stop
2000 rem INPUT+
2002 poke 23658,0 : let length=len z$
2004 for row=length to 1 step -1
2005if z$(row)=" " then CONTINUE FOR: end if : next xx
2006 let x$="*"
2008 print at 10,0; bright 1;z$( to row );x$;z$( row+1 to )
2010 let k=code inkey$ : if k then beep .02,0 : end if
2011 if k>31 and k<128 then goto 2264 : end if
2012 if k=13 then end :end if
2018 let row=0 : goto 2008
2020 goto 2004
2022 poke 23658,8 and not peek 23658 : goto 2006
2024 let z$="" : let row=0 : goto 2008
2026 if not row then goto 2010 : end if
2027 let row=row-1 : goto 2008
2028 if row=length then goto 2010 :end if
2029 let row=row+1 : goto 2008
2030 if row+32>length then goto 2010 :end if
2031 let row=row+32 : goto 2008
2032 if row<32 then goto 2010 : end if
2033 let row=row-32 : goto 2008
2034 if not row then goto 2010 : end if
2035 let row=row-1 : goto 2041
2036 print at 10,0;z$;">" : return
2038 goto 2010
2040 if row=length then goto 2010 : end if
2041 let z$( row+1 to )=z$( row+2 to ) : let z$(length)="" : goto 2008
2264 if row=150 then goto 2010 : end if
2265 let row=row+1 : if row<length then let z$( row+1 to )=z$( row to ):end if
2266 print k:let z$(row)=chr$(k) : goto 2008
2499 goto 2010



Re: Using inkey - ardentcrest - 02-21-2015

So much fun on this one. No matter what I do it almost works, but not quite works.


Re: Using inkey - boriel - 02-21-2015

ardentcrest Wrote:HUMMMMM. Posts when missing Sad

Need help. This compiles with no errors but still will not work. Any help.

Code:
2022 poke 23658,8 and not peek 23658 : goto 2006
Looking to line 2022. What are you trying to do here?


Re: Using inkey - ardentcrest - 02-21-2015

I believe that just flashes the cursor when a key is pressed.


Re: Using inkey - ardentcrest - 02-21-2015

ardentcrest Wrote:I believe that just flashes the cursor when a key is pressed.

Big Grin Big Grin Big Grin Got it working......

Code:
10 dim z$ : let z$="this is a test of an inkey$ editor                 " : gosub 2000 :stop
2000 rem INPUT+
2002 let length=len z$
2004 let row=32
2006 let x$="*"
2008 print at 10,0; bright 1;z$( to row );x$;z$( row+1 to )
2010 let k=code inkey$ : if k then beep .2,0 : end if
2011 if k>31 and k<128 then goto 2264 : end if
2012 if k=13 then goto 2036  :end if
2013 if k=8 then goto 2026  :end if
2014 if k=9 then goto 2028  :end if
2015 if k=10 then goto 2030  :end if
2016 if k=11 then goto 2032  :end if
2017 if k=12 then goto 2034  :end if
2018 if k=7 then goto 2024  :end if
2019 goto 2010


2026 if not row then goto 2010 : end if
2027 let row=row-1 : goto 2008
2028 if row=length then goto 2010 :end if
2029 let row=row+1 : goto 2008
2030 if row+32>length then goto 2010 :end if
2031 let row=row+32 : goto 2008
2032 if row<32 then goto 2010 : end if
2033 let row=row-32 : goto 2008
2034 if not row then goto 2010 : end if
2035 let row=row-1 : goto 2041
2036 print at 10,0;z$;">" : return
2038 goto 2010
2040 if row=length then goto 2010 : end if
2041 let z$( row+1 to )=z$( row+2 to ) : let z$(length)="" : goto 2008
2264 if row=150 then goto 2010 : end if
2265 let row=row+1 : if row<length then let z$( row+1 to )=z$( row to ) : end if
2266 let z$(row)=chr$(k) : goto 2008
2499 goto 2010

Silly me had a let row=0 in line 2018, just had to remove it :oops:

Just need now to work out how to get it to print in 42 or 64. And on the bottom two lines.

Still a bit buggy need to work on how ROW works.


Re: Using inkey - ardentcrest - 02-23-2015

Sorry Sorry sorry......

Code:
INK 7 : PAPER 0 : BORDER 0 : CLS

#include <keys.bas>

let length=60 : let rowx=0 : let xx$="<"

NETinputloop:

    if rowx=0 then print at 22,0;xx$ : goto NetJump1 : end if
    print at 22,0; : FOR ii = 0 TO rowx : print chr$(peek (@MyLabel + ii)); : NEXT ii : print xx$;"  "

NetJump1:
    let k=code inkey$ : if k then beep .2,0 : end if
    if k>31 and k<128 then goto NetKeyPress : end if
    if k=13 then end : end if
    if k=12 then goto NetDeleteKey : end if
    goto NetJump1

NetDeleteKey:
    if rowx=0 then goto NETinputloop : end if
    POKE (@MyLabel + rowx), 0
    let rowx=rowx-1
    goto NETinputloop

NetKeyPress:
    if rowx=length then goto NETinputloop : end if
    POKE (@MyLabel + rowx), k
    let rowx=rowx+1
    goto NETinputloop


    MyLabel:
    ASM
    text1:
    ds 1024  ;  1024 bytes of space MAX!!
    END ASM


    MyLabel2:
    ASM
    lenth1:
    ds 1  ;  1024 bytes of space MAX!!
    END ASM

When NetDeleteKey: it should move the cursor back but does not. What am I missing.


Re: Using inkey - ardentcrest - 02-23-2015

OK.............

GOT IT Big Grin

POKE (@MyLabel + rowx), 0 should be POKE (@MyLabel + (rowx-1)), 0

2 hours looking at that one.....