Qbasicnews.com
April 03, 2020, 07:45:49 AM *
Welcome, Guest. Please login or register.

Login with username, password and session length
News: Back to Qbasicnews.com | QB Online Help | FAQ | Chat | All Basic Code | QB Knowledge Base
 
   Home   Help Search Login Register  
Pages: [1]
  Print  
Author Topic: CHR$  (Read 3196 times)
tabnewflax
New Member

Posts: 22


« on: March 20, 2004, 07:34:42 PM »

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
Logged
Agamemnus
x/ \z
*****
Posts: 3491



« Reply #1 on: March 20, 2004, 07:38:43 PM »

1) 13. (no CHR$(0) in that one)
2) ... because.
Logged

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.
qbiscool
Member
*
Posts: 56


« Reply #2 on: March 20, 2004, 08:21:08 PM »

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
Logged

pen your other eyes.........
whitetiger0990
__/--\__
*****
Posts: 2964



WWW
« Reply #3 on: March 20, 2004, 09:53:22 PM »

@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
Logged


[size=10]Back by popular demand!
I will byte and nibble you bit by bit until nothing remains but crumbs.[/size]
Pyrodap
Senior Member
**
Posts: 166



« Reply #4 on: March 20, 2004, 10:43:14 PM »

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.
Logged
Agamemnus
x/ \z
*****
Posts: 3491



« Reply #5 on: March 20, 2004, 11:24:07 PM »

It's not space, it's CHR$(0).
Logged

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.
Sterling Christensen
Na_th_an
*****
Posts: 1328


« Reply #6 on: March 21, 2004, 01:10:46 AM »

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.
Logged
Moneo
Na_th_an
*****
Posts: 1971


« Reply #7 on: March 21, 2004, 01:36:14 AM »

As usual, great explanation, Sterling. Just the facts, no myths.
*****
Logged
Pyrodap
Senior Member
**
Posts: 166



« Reply #8 on: March 21, 2004, 03:28:46 AM »

oh yeah... no it isnt space. But yeah... whatever. you're right
Logged
tabnewflax
New Member

Posts: 22


« Reply #9 on: March 21, 2004, 09:13:51 AM »

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?
Logged
na_th_an
*/-\*
*****
Posts: 8244



WWW
« Reply #10 on: March 21, 2004, 09:41:23 AM »

1C is hexadecimal. Try &H1C
Logged

SCUMM (the band) on Myspace!
ComputerEmuzone Games Studio
underBASIC, homegrown musicians
[img]http://www.ojodepez-fanzine.net/almacen/yoghourtslover.png[/i
Neo
Na_th_an
*****
Posts: 2150



« Reply #11 on: March 22, 2004, 07:26:26 AM »

1Ch....

Hexadecimal:

256 16 1
  0    1  C
        |   |
        \-|-/
          |
       16*1 + 12*1 = 16 + 12 = 28
So ENTER's SCANCODe is 28.

You can get scancodes by:
Code:
FUNCTION neoKeybInkeyScan%
   sc% = INP(&H60)
   IF sc% >= 128 THEN sc% = 0
   neoKeybInkeyScan% = sc%
END FUNCTION
Logged
na_th_an
*/-\*
*****
Posts: 8244



WWW
« Reply #12 on: March 22, 2004, 10:21:05 AM »

You can also check them in the QB help, which is faster Tongue
Logged

SCUMM (the band) on Myspace!
ComputerEmuzone Games Studio
underBASIC, homegrown musicians
[img]http://www.ojodepez-fanzine.net/almacen/yoghourtslover.png[/i
Pages: [1]
  Print  
 
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.21 | SMF © 2015, Simple Machines Valid XHTML 1.0! Valid CSS!