Keyboard interfacing question
Hello,
I was wondering about keyboard input for the propeller;
does the keyboard object return strings or individual characters?
Thanks,
Devin
I was wondering about keyboard input for the propeller;
does the keyboard object return strings or individual characters?
Thanks,
Devin

Comments
The original demo displayed the hex code for the keys pressed.
My modified version (below) outputs both the character and the hex code.
CON _clkmode = xtal1 + pll16x _xinfreq = 5_000_000 OBJ term : "tv_terminal" kb : "keyboard" PUB start | i 'start the tv terminal term.start(12) term.str(string("Keyboard Demo...",13)) 'start the keyboard kb.start(26, 27) 'echo keystrokes in hex repeat result := kb.getkey term.out(result) term.out(" ") term.out("<") term.out("$") term.hex(result,3) term.out(">") term.out(" ")If you typed "Hello", the above code would display the following on the TV.
If you only wanted the characters you'd change the repeated section to this:
repeat term.out(kb.getkey)I wrote this demo a couple of hours ago.
I'll try the code!
Do you know of any objects that return keyboard input as strings?
Thanks,
Devin
PRI getline | i, c i := 0 repeat c := key.getkey if c == bspKey if i > 0 dsp.str(string(backspace," ",backspace)) i-- elseif c == fReturn dsp.out(c) tline[i] := 0 tp := @tline return elseif i < linelen-1 dsp.out(c) tline[i++] := cThis returns with the input string placed in the buffer "tline" and "tp" is set to the address of the first character. bspKey and backspace are different constants because bspKey is the backspace code returned by the keyboard driver while backspace is the character used by the display object for doing the backspace function (moving the cursor to the left).Any such object would return a pointer to the string or place the input in a predetermined buffer like Mike's code does. You don't really need an object to do this since now you have Mike's method.
Just add:
To your constant and variable section and use Mike's method to get a string from the keyboard. You can, of course, have "MAXSTR_LENGTH" be any size you want (within reason).
It looks like Mike's code checks for zero length prior to backspacing. It looks like he uses "linelen" as the limit to the size of sting. I used "MAXSTR_LENGTH" for this limit since PST uses this. It would have been better if I had used Mike's 'linelen" instead (assuming I'm reading Mike's code correctly).