Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
CHR$
#1
1. What is the character code for ENTER/RETURN?

2. Why do I have to write CHR$(0) before the input key,for example;

Code:
IF press$ = CHR$(0) + CHR$(75)...and so on
Reply
#2
1) 13. (no CHR$(0) in that one)
2) ... because.
Peace cannot be obtained without war. Why? If there is already peace, it is unnecessary for war. If there is no peace, there is already war."

Visit www.neobasic.net to see rubbish in all its finest.
Reply
#3
ya ive wodered why you have to wright chr$(0) + chr$(?) before the arrow keys and other keys to.

Quote:do
key$ = inkey$
if key$ <> "" then print key$
loop until key$ = chr$(27) and key$ = "q"

i think that code will work
anyways if you look at this and try it out you will see that it prints what key you press so hitting h will print a h and hitting q will print a q. But try pressing a arrow key and you will see that there is a space and then a letter. that means that you need a space and the code for that letter to make the arrow key you pressed.
the code for a space is chr$(0)

Quote:do
key$ = inkey$
if key$ <> "" then print "CHR$("asc(key$)") is = to "key$
loop

and if you run that code it should show you what to stick in to a chr$() to get the letter you pressed. So for example if you pressed A then you would get this output

CHR$(65) is = to A

Hope that helps and dont get mad if that code dusnt work because i didnt have time to test it out.

PS. and thanks for a question that i knew how to answer
pen your other eyes.........
Reply
#4
@qbiscool: your first example wont exit the loop when you press 'q' and esc for two reasons
1. a variable cant equal to things at once
2. inkey$ only gets one key at a time

if you meant to do that ignore me =P
[Image: sig.php]
Back by popular demand!
I will byte and nibble you bit by bit until nothing remains but crumbs.
Reply
#5
the reason that you do CHR$(0) + CHR$(?) is simple.


the INKEY$ for up is:

" H"

that is, SPACE + H.

another way to do it is this

IF RIGHT$(INKEY$, 1) = "H" THEN UPCODE


the letters are

H - up
P - down
K - left
M - right


but the CHR$(0) thing is better.
Reply
#6
It's not space, it's CHR$(0).
Peace cannot be obtained without war. Why? If there is already peace, it is unnecessary for war. If there is no peace, there is already war."

Visit www.neobasic.net to see rubbish in all its finest.
Reply
#7
Every key on your keyboard has a scancode. But only some of the keys on your keyboard have an ASCII code.

When the key has an ASCII code, INKEY$ returns that code in a single character string. When the key doesn't have one, INKEY$ returns CHR$(0) + CHR$([the key's scancode]).

QB's online help has a scancode table, which is great for figuring out what the two-character INKEY$ string for a key will be.
Reply
#8
As usual, great explanation, Sterling. Just the facts, no myths.
*****
Reply
#9
oh yeah... no it isnt space. But yeah... whatever. you're right
Reply
#10
Thanks 13 is the one...

To my next question when I read in the Qbasic helpsection it stands that ENTER is "1C" but it´s not working and no other key code is working either, what do I do wrong?
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)