Keyboard Scan Codes

If you have questions about any aspect of QBasic programming, or would like to help fellow programmers solve their problems, check out this board!

Moderators: Pete, Mods

Post Reply
User avatar
Halifax
Coder
Posts: 21
Joined: Thu Apr 07, 2005 4:20 pm
Location: utah

Keyboard Scan Codes

Post by Halifax »

Im using KeyRight, Left, Up, and Down right now. however, i have searched the internet and this site for the scan codes for other keys like esc etc but i cant get a straight answer.
right now i have this
KeyRight$ = chr$(77) + "P"
(this is quoted from memory, which means its wrong)
so how would i do esc?
KeyEsc$ = chr$(1) '?? that is what qbasic says ESC is... but it doesnt work
And you will come to find that we are all one mind, capable of all that's imagined and all conceivable - Maynard
User avatar
Mitth'raw'nuruodo
Veteran
Posts: 839
Joined: Sat Jan 22, 2005 11:04 am
Location: Eastern Coast of US
Contact:

Post by Mitth'raw'nuruodo »

inkey$ returns chr$(27) for esc
"But...It was so beutifully done"
Z!re
Veteran
Posts: 887
Joined: Wed Aug 04, 2004 11:15 am

Post by Z!re »

If inkey$ returns a two byte value, it is: chr(null)+chr(scancode)

Otherwise it's chr(asciicode)


Both scancodes and ascii codes can be found in the qb help.

Index->Character Scancodes
Index->Character ASCII Values
(or something)
I have left this dump.
User avatar
Mitth'raw'nuruodo
Veteran
Posts: 839
Joined: Sat Jan 22, 2005 11:04 am
Location: Eastern Coast of US
Contact:

Post by Mitth'raw'nuruodo »

Ya, something like that.
Z!re, I always wanted to ask this:
1. Whats with the first 30 ASCII codes, they don't work.
2. Whats with the Scancodes, they don't work.
"But...It was so beutifully done"
User avatar
{Nathan}
Veteran
Posts: 1169
Joined: Thu Aug 19, 2004 6:08 pm
Location: The wetlands of central Ohio, USA
Contact:

Post by {Nathan} »

to find a key, just type it while running this program.

Code: Select all

do
a$ = inkey
print src(a$)
loop
then you cana just

Code: Select all

 run this and find you chr value. src is the revverse of char, btw.
Image
Rattrapmax6
Veteran
Posts: 1055
Joined: Sun Jan 02, 2005 2:11 pm
Location: At my computer
Contact:

Post by Rattrapmax6 »

^_^, um nathan? you need:

LOCATE 1, 1: PRINT a$

Other wise it will scroll, :wink:

Here, this tut has a list of all the keyboard input codes that you'll probaly ever need::arrow: Basic to Advance keyboard programming :wink:
-Kevin (aka:Rattra)
(x.t.r.GRAPHICS)
User avatar
Mitth'raw'nuruodo
Veteran
Posts: 839
Joined: Sat Jan 22, 2005 11:04 am
Location: Eastern Coast of US
Contact:

Post by Mitth'raw'nuruodo »

Better yet:

Code: Select all

DO
 LOCATE 1, 1: PRINT INP(96)
LOOP
That is a better one then INKEY$
Not only do you have a set of numbers for every key on your keyboard (yes including Alt, Ctrl, Shift), But you have 2 sets for eaxh key. 1 set is when the key is pressed down, the other is after it has been released.
"But...It was so beutifully done"
Post Reply