WaitKey() and WaitChar()

BlitzMax Forums/BlitzMax Beginners Area/WaitKey() and WaitChar()

AKJ(Posted 2005) [#1]
I am writing a BlitzMax program (in Windows ME) that uses the Print command to output to a DOS window.

However, when the program ends the DOS window immediately terminates preventing me from seeing the results of the program. At the end of the source code I have tried using WaitKey() and WaitChar() to retain the DOS window but they do not appear to work as, despite pressing keys, these two commands do not unpend and I have to forcibly terminate the program.

For example the BlitzMax program below, fails to print "Done".

Print "Hello"
Print "Press any key ..."
WaitKey() ' Or WaitChar()
Print "Done"

What am I doing wrong?

If it is relevent, I am not using and do wish to use the Graphics command.

Anthony Jordan


Perturbatio(Posted 2005) [#2]
Will something like this do you?
Print "Hello"
Print "Press Enter..."
Global a : Byte
a= getc(stdin_)

While a = 255 
	a= getc(stdin_)
Wend
Print "Done" 


Extern 
	Function getc(stream:Int)
EndExtern




DNielsen(Posted 2005) [#3]
EDIT


FlameDuck(Posted 2005) [#4]
4 lines is a "LOT" of code?!? In which universe?


DNielsen(Posted 2005) [#5]
@Flameduck
you need to retake your math lessons. you cant count lines! ;-)

all it SHOULD take is 1 line! WAITKEY()! Everything else is a total waste


xlsior(Posted 2005) [#6]
all it SHOULD take is 1 line! WAITKEY()! Everything else is a total waste


Yes, it would be convenient if waitkey worked outside of graphic modes as well, but it doesn't.
It didn't work outside of graphic mode in the other blitz versions either, if I recall correctly.

Anyway, since you are essentially adding *new* functionality here, one hardly has a good reason to start running around in circles screaming that it's not fair because the workaround isn't a single built-in statement too.

(Of course Pertubatio's sample can easily be used as such, by wrapping it in a small function)


Perturbatio(Posted 2005) [#7]
Print "Hello"
Print "Press any Key"
getch()
End

Extern 
	Function getch()
EndExtern




AKJ(Posted 2005) [#8]
Thanks for all your suggestions.

I will adopt the getch() method, which although it fails to work (on my PC) whilst running a program in the IDE, functions perfectly well from within an .exe file and that is what I needed.

AKJ