Page 1 of 1
inkey$ question
Posted: Thu Oct 13, 2005 1:52 pm
by Captainlazy
Does anyone know the numbers of each keyboard character. I want to make a game character move with a single keypress but im not entirely sure how to do it. I seem to remember it being done by entering the the keyboard character number. Any ideas??
i know this is wrong but could someone correct this for me please...
IF inkey$ = "q" THEN characterposition = characterposition + 1
IF inkey$ = "w" THEN characterposition = characterposition + 2
IF inkey$ = "e" THEN characterposition = characterposition - 1
((ETC))
I will also need to know how to make it so that the program will not react to keypresses that i do not have a function for - eg. if they press H, the program will not do anything!!
Hope someone can help!!
Posted: Thu Oct 13, 2005 2:34 pm
by Z!re
I'm not really sure what you mean..
The ASCII codes? There's a table in QB, Help->Content->ASCII
IF inkey$ = "q" THEN characterposition = characterposition + 1
IF inkey$ = "w" THEN characterposition = characterposition + 2
IF inkey$ = "e" THEN characterposition = characterposition - 1
Is not wrong at all, it's just how you'd do it.. Unless I'm missunderstanding you..
Posted: Thu Oct 13, 2005 3:00 pm
by MystikShadows
Here's some standard keyboard keys I use everywhere (make the code more readable
. followed by a small sample how to use them.
Code: Select all
CONST KeyF1 = 59
CONST KeyF2 = 60
CONST KeyF3 = 61
CONST KeyF4 = 62
CONST KeyF5 = 63
CONST KeyF6 = 64
CONST KeyF7 = 65
CONST KeyF8 = 66
CONST KeyF9 = 67
CONST KeyF10 = 68
CONST KeyF11 = 133
CONST KeyF12 = 134
CONST KeyEscape = 27
CONST KeyInsert = 82
CONST KeyDelete = 83
CONST KeyHome = 71
CONST KeyEnd = 79
CONST KeyPageUp = 73
CONST KeyPageDown = 81
CONST KeyUpArrow = 72
CONST KeyDownArrow = 80
CONST KeyLeftArrow = 75
CONST KeyRightArrow = 77
CONST KeyBackspace = 14
CONST KeyTabulation = 15
CONST KeyLeftShift = 42
CONST KeyRightShift = 54
CONST KeyAlternate = 56
CONST KeyControl = 29
CONST KeyCapsLock = 58
CONST KeyNumlock = 69
CONST KeyScrollLock = 70
Keycode$ = ""
DO WHILE CanExit = 0
' Wait for a key to be pressed
DO WHILE LEN(Keycode$) = 0
KeyCode$ = INKEY$
LOOP
SELECT CASE KeyCode$
CASE CHR$(0) + CHR$(KeyUpArrow)
CharacterYPosition = CharacterYPosition - 1
CASE CHR$(0) + CHR$(KeyDownArrow)
CharacterYPosition = CharacterYPosition + 1
CASE CHR$(0) + CHR$(KeyLeftArrow)
CharacterXPosition = CharacterXPosition - 1
CASE CHR$(0) + CHR$(KeyRightArrow)
CharacterXPosition = CharacterXPosition + 1
END SELECT
LOOP
This should be the loop you need. In each CASE you can add code to do what you want
Hope this helps
Posted: Thu Oct 13, 2005 4:01 pm
by {Nathan}
One word (err... statement): ASC.
For expample.
That would put the ASCII (hence the ASC(II)) code of H into Hi%.
Posted: Thu Oct 13, 2005 4:38 pm
by Patz QuickBASIC Creations
Nathan1993: You forgot your quotes around your H
Try this out, captainlazy
Code: Select all
WHILE KEY$ <> CHR$(27) 'Makes the program stop if ESC is pressed.
WHILE KEY$ = ""
Key$ = INKEY$
WEND
IF Key$ = "(your letter IN QUOTES)" THEN (insert your functions here)
' and more keywords
IF KEY$ <> CHR$(27) THEN KEY$ = "" 'Resets the key holder
WEND
SYSTEM 'Shuts down the program
If you need ASCII codes, just go to your QB's Help Contents and click ASCII Character Codes.
Posted: Thu Oct 13, 2005 5:30 pm
by {Nathan}
PQBC wrote:Nathan1993: You forgot your quotes around your H
Try this out, captainlazy
Code: Select all
WHILE KEY$ <> CHR$(27) 'Makes the program stop if ESC is pressed.
WHILE KEY$ = ""
Key$ = INKEY$
WEND
IF Key$ = "(your letter IN QUOTES)" THEN (insert your functions here)
' and more keywords
IF KEY$ <> CHR$(27) THEN KEY$ = "" 'Resets the key holder
WEND
SYSTEM 'Shuts down the program
If you need ASCII codes, just go to your QB's Help Contents and click ASCII Character Codes.
I cannot believe I forgot that quote... and that my shift key worked twice in a row! (8 times now)!!!
I must have fixed it.
Posted: Thu Oct 13, 2005 5:33 pm
by Patz QuickBASIC Creations
Nathan1993 wrote:One word (err... statement): ASC.
For expample.
That would put the ASCII (hence the ASC(II)) code of H into Hi%.
I guess that wasn't your day. You forgot the quotes AND spelled example wrong!
Posted: Fri Oct 14, 2005 2:26 am
by Captainlazy
[quote="PQBC"]
Try this out, captainlazy
Code: Select all
WHILE KEY$ <> CHR$(27) 'Makes the program stop if ESC is pressed.
Cheers guys, this is exactly the kind of thing i was looking for.
Posted: Fri Oct 14, 2005 4:49 pm
by Patz QuickBASIC Creations
yay! Finally I'm the hero!!!
Posted: Sat Oct 15, 2005 9:28 am
by {Nathan}
PQBC wrote:yay! Finally I'm the hero!!!
As if you weren't before? What about that puny windows clone that ACTUALLY fit into your sig, and was less than 1 kb? Heres my version;
Code: Select all
shell "Pause"
Print "Fatal error. Must... die..."
shell "pause"
end
untested... just like windows. unsure if the shells will work, but they do in c++.
Posted: Mon Oct 17, 2005 4:54 pm
by Patz QuickBASIC Creations
Better copy the code while you can... I hear Microsoft is searching for my ass for releasing the source to their cash cow
ROFL
Posted: Mon Oct 17, 2005 5:17 pm
by Guest
No, you're to minor in their to do list for them to even care...
Posted: Mon Oct 17, 2005 6:31 pm
by {Nathan}
PQBC wrote:Better copy the code while you can... I hear Microsoft is searching for my ass for releasing the source to their cash cow
ROFL
... (searches for a jump drive. Hides it in the vent.)
Posted: Wed Oct 19, 2005 5:41 pm
by Patz QuickBASIC Creations
(uses AutoClave [awesome erasing tool - useful against hackers] in binary overwrite mode[25 layer delete, secure against NASA, takes about a day and a third to run] 5 times for a total of one week)
Let's see Microsoft try to trace me now!