Trouble reading KeyDown and KeyHit in BlitzPlus
Blitz3D Forums/Blitz3D Beginners Area/Trouble reading KeyDown and KeyHit in BlitzPlus
| ||
When I try to use a while loop until a key is pressed in BlitzPlus, it never seems to read the keyboard. I tried adding the Flip command before Wend and also switched to a ps2 keyboard to see if my USB KVM was cauing problems... Same thing. It never breaks out of the loop. I have also tried using KeyHit. ;demo03-04.bb - Waits for a key and then exits Print "This program is worthless." Print "Press escape to exit." ;Wait until user presses 1 to Escape ;While Loop While Not KeyDown(1) ;WaitKey Flip Wend End |
| ||
KeyDown(1) is the ESC key KeyDown(2) is the number 1 key KeyDown(3) is the number 2 key KeyDown(4) is the number 3 key etc. Are you sure you're pressing the correct key? By the way, adding Flip has nothing to do with KeyDown() Also by the way, if you just want to wait for a keypress you can just use WaitKey() and forget about the loop bit you have there(unless of course, you want something else to happen inside of the loop). |
| ||
I pressed the ESC key and it still does nothing. I am just learning so I want to be able to read the KeyDown or KeyHit when necessary to read different keys. The following code did not even work: ***** Print "This program is worthless." Print "Press escape to exit." ;Wait until user any key to escape WaitKey End ***** I'm just trying to use simple examples to learn, but would think that the code above would work. Am I missing something simple? |
| ||
try putting:EnableDirectInput True at the beginning and see if that solves it. *EDIT* Note: I have B3D not B+, but it may still have that command. |
| ||
I tried that but it said that that command does not exist. |
| ||
Bum... ah well it was worth a try. Do you have any special hardware or software installed? Did your keyboard come with it's own custom drivers? (I realise a normal keyboard will work straight out the box, but some have special features). |
| ||
This machine is a Dell PowerEdge 600SC, P4 1.8 Ghz, 1GB RAM, nVidia GeForce4 440 MX, SoundBlaster Live!... I have it hooked up to a USB KVM with Sound. I thought that may be a problem so I plugged in a ps2 keyboard. No dice... It's strange because the functions seem to work except when used with the while loops. |
| ||
(Also I'm running Windows Server 2003) The "repeat" loop also acts the same... Print "Why did you open this progam?" Repeat Print "Press Esc to exit." ;wait a sec Delay 1000 ;repeat until user hits esc Flip Until KeyHit(1) Print "Program is ending." |
| ||
(P4 - 2.4GHz... In case someone let's me know that they don't make a 1.8) :-) |
| ||
BlitzPlus differs from Blitz3D by having a console mode. If you don't use a Graphics statement then you are in console mode. In this case you get input with the Input statement and display output with Print and Write. With a Graphics window you can use the various Key commands. Graphics 400, 300, 0, 2 Text 130, 140, "Escape quits." While Not KeyDown(1) ; nothing Wend |
| ||
That make sense because the graphics examples work (as long as I insert "Flip" commands after drawing). I believe the book I am learning from would have worked better with Blitz3D which must be closer to the BlitzBasic used in the examples. The book is called "Game Programming for Teens" Does Blitz3D not have a console mode then? And I suppose these examples would work fine in Blitz3D which then is always in graphics mode and wouldn't need the graphics comand unless changing or setting the resolution? |
| ||
Blitz3D starts in console mode as well. |
| ||
just remember to set the buffer to write to:Graphics 640,480,0,1 SetBuffer BackBuffer() While Not KeyDown(1) Text 10,10,"This program is worthless." Text 10,30,"Press Esc to exit" Flip Wend End |
| ||
Thanks that helps a lot. I am trying to rewrite the example code from "Game Programming For Teens" to work with BlitzPlus. |
| ||
Cool. because it is a bit misleading to say B+ is compatible with B2D. Correct, but misleading, cos people expect the code will run, and it won't :) Not without a bit of tweaking :) |