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 : Show cursor during inputs?
Author | Message | ||||
Grogster Admin Group Joined: 31/12/2012 Location: New ZealandPosts: 9308 |
Hello folks. Further to my other thread about building a string from seperate keypresses, so that I can use the TIMER during the loops, to auto-exit if no key is pressed - all that instead of using LINE INPUT - here is the working test code: [code] start: do timer=0 do k$=inkey$ loop until k$<>"" or timer>10000 if asc(k$)=13 then print "ENTER pressed. Resultant string is:" print out$ end endif if asc(k$)=8 then if len(out$)=0 then goto start out$=left$(out$,len(out$)-1) print k$; else out$=out$ + k$ print k$; endif if timer>10000 then print "Time's up!" end endif loop [/code] This just takes keyboard input, and puts it in a string one key at a time, accounting for backspace, and using ENTER to signal the end of input in the normal way. This is working fine, but I have no cursor. This is not really any problem, until you press BS. Although the BS is working in the processing of the output string, with no cursor, you can't see where you are in the scheme of things. Is there any way to show the cursor when doing this kind of thing a-la the LINE INPUT cursor which is automatically put there by MM BASIC? Smoke makes things work. When the smoke gets out, it stops! |
||||
TassyJim Guru Joined: 07/08/2011 Location: AustraliaPosts: 6100 |
Try this one: start:
cls do print @(100,100) "Input here: "+out$+"_ " timer=0 do k$=inkey$ loop until k$<>"" or timer>10000 if asc(k$)=13 then alldone=1 endif if asc(k$)=8 then if len(out$)<2 then out$="" else out$=left$(out$,len(out$)-1) endif else out$=out$ + k$ print k$; endif if timer>10000 then alldone=2 endif loop until alldone >0 if alldone=1 then print "ENTER pressed. Resultant string is:" print out$ elseif alldone=2 then print "Time's up!" endif end I have used the underscore as a basic cursor. You could play with reverse video for the cursor as well Jim VK7JH MMedit MMBasic Help |
||||
Grogster Admin Group Joined: 31/12/2012 Location: New ZealandPosts: 9308 |
Thanks, Jim - I will copy that into MMedit, and zap it across the USB and try it out from there. Smoke makes things work. When the smoke gets out, it stops! |
||||
Grogster Admin Group Joined: 31/12/2012 Location: New ZealandPosts: 9308 |
Yep, that seems to work well - thanks. I will port this across to the working code. It's a bit more code then the single line LINE INPUT, but hey - C'est La Vie... ...and I can use this code to auto-exit back to the main menu which I can't do with LINE INPUT. Smoke makes things work. When the smoke gets out, it stops! |
||||
Grogster Admin Group Joined: 31/12/2012 Location: New ZealandPosts: 9308 |
OK, here is the finished working routine: [code] '------------------- ' SEND A MESSAGE: '------------------- If Asc(key$)=147 Then GoSub MenuBox Font 2 Print @(25,17) + CLR$(Yellow) "SEND A MESSAGE:" Font 1 Print @(20,65) + CLR$(Green) "Type your message below, and press "; Print @(20,80) + CLR$(White) "ENTER" + CLR$(Green) ", or just press "; Print CLR$(White) "ENTER" + CLR$(Green) " now for"; Print @(20,95) + CLR$(Green) "the main menu screen." Print @(10,140) + CLR$(White) ">"; do timer=0 print @(20,140) out$ + "_ " do k$=inkey$ loop until k$<>"" or timer>10000 if timer>10000 then out$="" goto start endif if asc(k$)=13 then If out$="" Then GoTo start GoSub MenuBox Font 2 Print @(20,100) + CLR$(Red) "TRANSMITTING..." SM$="CA" + RIC2$ + "1" Print #1,SM$ Pause 250 Print #1,out$ Pause 250 GoTo start endif if asc(k$)=8 then if len(out$)=0 then goto start out$=left$(out$,len(out$)-1) else out$=out$ + k$ endif loop endif [/code] I list this here, so others can see what we have come up with - might be useful for others wanting to do the same thing as me. Jim's code has been altered a little, but the basic idea is still the same. COM1 is #1, and has a pager transmitter connected to it. The port is setup, back at the start of the code, so there is no OPEN command shown here - I just mention that for clarification. This code will build a string based on your keyboard input, and store it in out$, and show it on the screen with a stationary cursor using Jim's idea. If you just press ENTER without typing anything, the code exits back to start:, which is the main menu. If you don't press a key for ten seconds, the code auto-exits back to the main menu. EDIT: Found a bug in this already! If you press BS as the first character, the code falls over with an error message - I will fix this, and update the code shown here... EDIT: BS bug fixed. Pressing BS or ENTER as the first character just exits back to the main menu. I am starting to like these structured loops. As someone who pretty much wrote each routine separately, then used GOTO's to hop around the code, this is a bit of learning for me to take in, but things like this routine show how useful a technique these things are! I have already changed most of the GOTO's in the original code, to have the GOTO-ed code sit within the IF/THEN/ELSE/ENDIF ideas, and then have all these inside a main DO/LOOP, and it was easier then I thought to get it all changed and working, so I am learning! Smoke makes things work. When the smoke gets out, it stops! |
||||
Grogster Admin Group Joined: 31/12/2012 Location: New ZealandPosts: 9308 |
UPDATE - Now auto-exits with any key other then numbers and letters, so if you try to use arrows, function keys etc, it will auto-exit. BS does not exit anymore, even if it is the first key pressed. [code] '------------------- ' SEND A MESSAGE: '------------------- If Asc(key$)=147 Then GoSub MenuBox Font 2 Print @(25,17) + CLR$(Yellow) "SEND A MESSAGE:" Font 1 Print @(20,65) + CLR$(Green) "Type your message below, and press "; Print @(20,80) + CLR$(White) "ENTER" + CLR$(Green) ", or just press "; Print CLR$(White) "ENTER" + CLR$(Green) " now for"; Print @(20,95) + CLR$(Green) "the main menu screen." Print @(10,140) + CLR$(White) ">"; do timer=0 print @(20,140) out$ + "_ " do k$=inkey$ loop until k$<>"" or timer>10000 if timer>9000 then out$="" goto start endif if asc(k$)>=0 and asc(k$)<=7 or asc(k$)>=9 and asc(k$)<=12 then out$="" goto start endif if asc(k$)>=14 and asc(k$)<=31 or asc(k$)>=128 and asc(k$)<=156 then out$="" goto start endif if asc(k$)=13 then If out$="" Then GoTo start GoSub MenuBox Font 2 Print @(20,100) + CLR$(Red) "TRANSMITTING..." SM$="CA" + RIC2$ + "1" Print #1,SM$ Pause 250 Print #1,out$ Pause 250 GoTo start endif if asc(k$)=8 and len(out$)>=1 then out$=left$(out$,len(out$)-1) else out$=out$ + k$ endif if len(out$)=1 then if asc(out$)=8 then out$="" endif loop endif [/code] Smoke makes things work. When the smoke gets out, it stops! |
||||
Print this page |