Page 1 of 1

Using the arrow keys with Key On?

Posted: Mon Oct 17, 2005 5:36 am
by Stevo
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

Posted: Mon Oct 17, 2005 5:38 am
by Guest
oops. And 35 is the keyboard scancode for H, to clarify why I used the value 35.

Posted: Tue Oct 18, 2005 12:36 am
by Mystery Meat!
You can get the list of Key scan code here...

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


Hope it helps...

Define keys

Posted: Tue Oct 18, 2005 10:32 pm
by Valerie
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

Posted: Fri Oct 21, 2005 6:21 am
by Stevo
Works like a charm, much appreciated!!

Posted: Sun Oct 23, 2005 8:39 am
by Bjorn
What are you making?