Announcement

Collapse
No announcement yet.

ASCII and HEX

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • ASCII and HEX

    I was searching through help files about the KEY statement when I found an example on setting CTRL + S as a KEY. Here is what it used to set that KEY: KEY 15, CHR$(&H4) + CHR$(&H1F). I find using HEX is confusing to me so I converted it to ASCII, being that CTRL = 4 and lowercase S = 115: KEY 15, CHR$(4) + CHR$(115). For some reason it doesn't read CHR$(115) as "s", it reads it as something else, and I don't know why. So I built a HEX to Decimal converter, I entered &H1F and it came out as CHR$(31). Why is that?

  • #2
    Because &H1F = 31, I expect. But, perhaps that's not the question you had in mind.

    The reason ASCII codes don't work here is, KEY isn't designed to work with ASCII codes. In order to provide more flexibility, KEY works with the keyboard at a lower level, before the keys pressed are translated into ASCII codes. What KEY expects is a keyboard scan code, which provides sort of a raw indication of which key is pressed, without regard for shift, control, ALT, or other modifiers.


    ------------------
    Tom Hanlin
    PowerBASIC Staff

    Comment


    • #3
      Thank you for your reply, I kind of figured that out a little while after I posted this topic but I wasn't able to edit my post afterwords. It uses Scan Codes. I have another question that runs off this topic. In Qbasic your able to us the GOSUB command like so: ON KEY(15) GOSUB ThisPlace, ThatPlace. This means that it goes to "ThisPlace" and then on return it goes to "ThatPlace". Is there a way to do a similar GOSUB like this for PowerBasic? Because this way doesn't work.

      Comment


      • #4
        In Qbasic your able to us the GOSUB command like so: ON KEY(15) GOSUB ThisPlace, ThatPlace. This means that it goes to "ThisPlace" and then on return it goes to "ThatPlace". Is there a way to do a similar GOSUB like this for PowerBasic? Because this way doesn't work.
        QBasic does not allow the "ThatPlace", nor does PowerBASIC.

        You may have this confused with..
        Code:
          RETURN  label
        ..in the GOSUB referenced by the ON KEY

        While "RETURN label" would probably work under PB/DOS, it looks a little awkward. If your really want to "GOSUB ThisPlace," then "GOSUB ThatPlace" on return, you can do this:
        Code:
        ThisPlace:
          Do stuff
        ThatPlace:
          Do more stuff
          RETURN

        That said, "RETURN Label" should be used with extreme circumspection, as it has a great potential to generate spaghetti code.


        MCM


        Michael Mattias
        Tal Systems Inc. (retired)
        Racine WI USA
        [email protected]
        http://www.talsystems.com

        Comment

        Working...
        X