Using the arrow keys with Key On?

Please use this Board for QBasic related requests ( file research, programming, etc.)

Moderators:Administrator, Global Moderator

Post Reply
Stevo
Using the arrow keys with Key On?

Post by Stevo » Mon Oct 17, 2005 5:36 am

Hey all! This looks like a great board. kudos on being one of the more lively QB communities.

My question is, how do you trap the cursor keys for use with the KEY (N) statement? I've found out how to do the Numeric Keypad arrow keys, like 8/up and 6/right, etc. But is there any way to do this with the cursor keys themselves?
My guess would be this:

KEY 15, CHR$(0) + CHR$(35)
KEY 15 ON

10
ON KEY(15) Gosub UpArrow
GOTO 10

UpArrow:
print "UP"
end

However, this doesn't work. I used 35 for the letter H, because when you do an inkey$ loop, I've always seen the up arrow key used like this:
if inkey$ = chr$(0) + "H" then Gosub UpArrow.
So I figured this would also work with KEY statements, but no dice. Anyone have any suggestions?
Thanks in advance,
Stevo

Guest

Post by Guest » Mon Oct 17, 2005 5:38 am

oops. And 35 is the keyboard scancode for H, to clarify why I used the value 35.

Mystery Meat!

Post by Mystery Meat! » Tue Oct 18, 2005 12:36 am

You can get the list of Key scan code here...

http://www.qbasicnews.com/qboho/qckadvr.kbsct.shtml


Hope it helps...

Valerie
Sr. Member
Posts:54
Joined:Wed Dec 15, 2004 8:10 am
Location:Coromandel, NZ

Define keys

Post by Valerie » Tue Oct 18, 2005 10:32 pm

This works for me:

' keyboard definitions
KEY 15, CHR$(0) + CHR$(1) ' Define ESC key
KEY 18, CHR$(128) + CHR$(72) ' Define uparrow
KEY 19, CHR$(128) + CHR$(80) ' Define downarrow
KEY 20, CHR$(128) + CHR$(77) ' Define rightarrow
KEY 21, CHR$(128) + CHR$(75) ' Define leftarrow

Stevo

Post by Stevo » Fri Oct 21, 2005 6:21 am

Works like a charm, much appreciated!!

Bjorn

Post by Bjorn » Sun Oct 23, 2005 8:39 am

What are you making?

Post Reply