inkey$ question
- Captainlazy
- Newbie
- Posts: 8
- Joined: Tue Oct 11, 2005 12:39 pm
- Location: UK
inkey$ question
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!!
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!!
I'm not really sure what you mean..
The ASCII codes? There's a table in QB, Help->Content->ASCII
The ASCII codes? There's a table in QB, Help->Content->ASCII
Is not wrong at all, it's just how you'd do it.. Unless I'm missunderstanding you..IF inkey$ = "q" THEN characterposition = characterposition + 1
IF inkey$ = "w" THEN characterposition = characterposition + 2
IF inkey$ = "e" THEN characterposition = characterposition - 1
I have left this dump.
-
- Veteran
- Posts: 703
- Joined: Sun Nov 14, 2004 7:36 am
- Contact:
Here's some standard keyboard keys I use everywhere (make the code more readable . followed by a small sample how to use them.
This should be the loop you need. In each CASE you can add code to do what you want
Hope this helps
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
Hope this helps
When God created light, so too was born, the first Shadow!
MystikShadows
Need hosting? http://www.jc-hosting.net
Interested in Text & ASCII development? Look no further!
http://www.ascii-world.com
MystikShadows
Need hosting? http://www.jc-hosting.net
Interested in Text & ASCII development? Look no further!
http://www.ascii-world.com
- {Nathan}
- Veteran
- Posts: 1169
- Joined: Thu Aug 19, 2004 6:08 pm
- Location: The wetlands of central Ohio, USA
- Contact:
One word (err... statement): ASC.
For expample.
That would put the ASCII (hence the ASC(II)) code of H into Hi%.
For expample.
Code: Select all
Hi% = ASC(H)
-
- Veteran
- Posts: 399
- Joined: Wed Mar 02, 2005 9:01 pm
- Location: Nashville, Tennessee
- Contact:
Nathan1993: You forgot your quotes around your H
Try this out, captainlazy
If you need ASCII codes, just go to your QB's Help Contents and click ASCII Character Codes.
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
- {Nathan}
- Veteran
- Posts: 1169
- Joined: Thu Aug 19, 2004 6:08 pm
- Location: The wetlands of central Ohio, USA
- Contact:
I cannot believe I forgot that quote... and that my shift key worked twice in a row! (8 times now)!!!PQBC wrote:Nathan1993: You forgot your quotes around your H
Try this out, captainlazyIf you need ASCII codes, just go to your QB's Help Contents and click ASCII Character Codes.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
I must have fixed it.
-
- Veteran
- Posts: 399
- Joined: Wed Mar 02, 2005 9:01 pm
- Location: Nashville, Tennessee
- Contact:
I guess that wasn't your day. You forgot the quotes AND spelled example wrong!Nathan1993 wrote:One word (err... statement): ASC.
For expample.
That would put the ASCII (hence the ASC(II)) code of H into Hi%.Code: Select all
Hi% = ASC(H)
- Captainlazy
- Newbie
- Posts: 8
- Joined: Tue Oct 11, 2005 12:39 pm
- Location: UK
[quote="PQBC"]
Try this out, captainlazy
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.
-
- Veteran
- Posts: 399
- Joined: Wed Mar 02, 2005 9:01 pm
- Location: Nashville, Tennessee
- Contact:
- {Nathan}
- Veteran
- Posts: 1169
- Joined: Thu Aug 19, 2004 6:08 pm
- Location: The wetlands of central Ohio, USA
- Contact:
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;PQBC wrote:yay! Finally I'm the hero!!!
Code: Select all
shell "Pause"
Print "Fatal error. Must... die..."
shell "pause"
end
-
- Veteran
- Posts: 399
- Joined: Wed Mar 02, 2005 9:01 pm
- Location: Nashville, Tennessee
- Contact:
-
- Veteran
- Posts: 399
- Joined: Wed Mar 02, 2005 9:01 pm
- Location: Nashville, Tennessee
- Contact: