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
1) 13. (no CHR$(0) in that one)
2) ... because.
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
@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
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.
It's not space, it's CHR$(0).
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.
As usual, great explanation, Sterling. Just the facts, no myths.
*****
oh yeah... no it isnt space. But yeah... whatever. you're right
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?