×
INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Contact US

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

Question

Question

Question

(OP)
Hello,
Does anyone know the keyboard map for all the keys to use with the onkey command ?  I tried to use the same onkey codes with qbasic as I used to use with gwbasic.  I need the codes for the arrow keys (seperate pad not numeric keys).  Can anyone help ?

RE: Question

Check the help. It is pretty good in this area.

RE: Question

I don't know the code to use with the onkey funtion but maybe this could help

*****  P = down, H = up, K = left, M = right  *****^

CODE

k$ = INKEY$
If k$ = Chr$(0) + "M" Then
   rem right Arrow
   rem ...
end if
If k$ = Chr$(0) + "K" Then
   rem left arrow
   rem ...
end if
If k$ = Chr$(0) + "H" Then
   rem up arrow
   rem ...
end if
If k$ = Chr$(0) + "P" Then
   rem down arrow
   rem ...
end if

SkyFighter
skyfighta@hotmail.com
Get the fun out of life!

RE: Question

(OP)

Programmers,
OK, the qbasic.hlp helped a lot.  Thank you. Now I have another problem when I continue to use the arrow keys I get an out of stack space error.  How can I supress this ?
Here is the code:

' Findkey.bas used to find what key is pressed

    DEFINT A-Z
CLS
start:
  KEY(11) ON
  KEY(12) ON
  KEY(13) ON
  KEY(14) ON

 ON KEY(11) GOSUB a
 ON KEY(12) GOSUB b
 ON KEY(13) GOSUB c
 ON KEY(14) GOSUB d
GOTO start
a:
PRINT "up"
GOTO start
b:
PRINT "left"
GOTO start
c:
PRINT "right"
GOTO start
d:
PRINT "down"
GOTO start

RE: Question

From a GOSUB, you have to use a RETURN statement.  That's what's causing the stack error.

Lee

RE: Question

lived's example is MUCH cleaner and more in line with modern coding style.  The old GOSUB is left over from pre-Q days and is included to make it compatible with older code.

Lee

RE: Question

(OP)
Thank you, for all your help it was valuable, I guess the best way to learn is to get both feet in, and try.  The code is old, but hey it works !  Lee you hit the nail on the head !  Return of course !

RE: Question

gosub is still used a lot.

Rather than using on key, you might just capture the key and process it using inkey$ for example.

theloop:
a$=inkey$
if len(a$)=2 then gosub process.control.input:goto theloop
if a$=chr$(8) then 'backspace
.
.
end if
if a$=chr$(13) then '$CR
.
.
end if
process.control.input:
if left$(a$,1)=chr$(0) then
 select case right$(a$,1)
  case ...
 end select
end if
return

RE: Question

I don't know why you would use GOSUB instead of processing all the items into 1 select statement. As trollacious said, GOSUB are not used anymore, it is only left out for compatibility, since you can do better with SELECT and SUB statements, and it takes more memory than needed for something you could easily do another way. It's not because you use it a lot that it should be. Keep it simple and efficient.

CODE

CLS
DO
    k$ = INKEY$
    SELECT CASE k$
    CASE CHR$(27)
        PRINT "escape key"
        INPUT "do you wanna exit (Y or N)", yn$
        IF UCASE$(left$(yn$,1)) = "Y" THEN END

    CASE CHR$(8)
        PRINT "backspace key"
    CASE CHR$(13)
        PRINT "enter key"
    CASE CHR$(0) + "P"
        PRINT "down arrow"
    CASE CHR$(0) + "H"
        PRINT "up arrow"
    CASE CHR$(0) + "K"
        PRINT "left arrow"
    CASE CHR$(0) + "M"
        PRINT "right arrow"
    END SELECT
LOOP

SkyFighter
skyfighta@hotmail.com
Get the fun out of life!

RE: Question

you should investigate Inp(96) (aka Inp(&60))

you might want to look at...

Thread314-709202

or

Thread314-431683

>> seperate pad not numeric keys

*Note: the keys are actually mapped the same... the only difference is the NumLock key status...

both sets of keys return the following ScanCodes:
72 - Up
75 - Left
77 - Right
80 - Down

Have Fun, Be Young... Code BASIC
-Josh


http://cubee.topcities.com

PROGRAMMER: (n) Red-eyed, mumbling mammal capable of conversing with inanimate objects.

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members! Already a Member? Login

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close