Shop OBEX P1 Docs P2 Docs Learn Events
Storing value of keyboard — Parallax Forums

Storing value of keyboard

Dan TaylorDan Taylor Posts: 207
edited 2009-04-15 16:03 in Propeller 1
Hi,
I am having a little trouble with the keyboard that comes with the accessories kit. How can I get the output of the keyboard and store it into a variable. And then say,
IF key = 100·THEN
·· ...
IF key = 101 THEN
·· ...

Can someone show me some example code or just explain it to me...
Many Thanks!



▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Dan Taylor

Comments

  • StefanL38StefanL38 Posts: 2,292
    edited 2009-04-14 16:51
    Hello Dan,

    in the folder ...\Propeller-Tool\examples\Library\

    there is a file Keyboard_Demo.spin.

    You can use this demo as a start.

    best regards

    Stefan
  • Dan TaylorDan Taylor Posts: 207
    edited 2009-04-14 18:08
    ok, so I think I found out how to get the key code! But displaying it on the Display is still not there yet. So to get the keycode I have done:

    kb : "keyboard"

    term : "tv_terminal"

    IF kb.getkey =·97 then

    · term.str("a")

    But the "a" is never displayed just some random characters. Is it converting it to hexadecimel or something?



    ·····

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Dan Taylor
  • John AbshierJohn Abshier Posts: 1,116
    edited 2009-04-14 18:51
    replace
    term.str("a")
    with
    term.str(string("a"))

    I don't know if term.out("a") will work.

    John Abshier
  • Dan TaylorDan Taylor Posts: 207
    edited 2009-04-14 19:12
    That is what my problem was.

    Thank you both for your help!

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Dan Taylor
  • Dan TaylorDan Taylor Posts: 207
    edited 2009-04-15 02:09
    Do any of you know how I could by clicking backspace do a simple backspace on the display?

    Thanks!

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Dan Taylor
  • Mike GreenMike Green Posts: 23,101
    edited 2009-04-15 02:21
    You're using tv_terminal.spin which doesn't really have any provisions for a backspace operation. It treats the screen as a graphics display rather than a text display and draws characters rather than just putting them up in "cells". There is an "out" routine that does the interpreting of characters including tab and return. You could add a case for the backspace character ($08) and use either gr.quad or gr.box to erase the previous character's area on the display.

    If you're just displaying text, you could use one of the text drivers like tv_text which does handle the backspace.
  • Dan TaylorDan Taylor Posts: 207
    edited 2009-04-15 16:03
    Oh nice! I didn't see the TV_text program.

    Thank you all for your help! I really appreciate it!

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Dan Taylor
Sign In or Register to comment.