Posts: 22
Threads: 9
Joined: Mar 2004
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
Posts: 3,368
Threads: 195
Joined: Jan 2003
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.
Posts: 53
Threads: 13
Joined: Feb 2004
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.........
Posts: 2,765
Threads: 138
Joined: Nov 2002
@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
Back by popular demand!
I will byte and nibble you bit by bit until nothing remains but crumbs.
Posts: 144
Threads: 17
Joined: Jan 2004
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.
Posts: 3,368
Threads: 195
Joined: Jan 2003
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.
Posts: 1,272
Threads: 36
Joined: Feb 2003
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.
Posts: 1,956
Threads: 65
Joined: Jun 2003
As usual, great explanation, Sterling. Just the facts, no myths.
*****
Posts: 144
Threads: 17
Joined: Jan 2004
oh yeah... no it isnt space. But yeah... whatever. you're right
Posts: 22
Threads: 9
Joined: Mar 2004
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?