Page 1 of 2

"Press any key to continue . . ." for console apps

Posted: Sat Dec 27, 2008 3:26 am
by Mistrel

Code: Select all

RunProgram("cmd.exe","/k pause","")
End
:)

Posted: Sat Dec 27, 2008 3:30 am
by Rook Zimbabwe
But... but... my keyboard doesn't HAVE an ANY key!!! :wink:

Seriously nice idea Mistrel! :D

Posted: Sat Dec 27, 2008 3:50 am
by Kaeru Gaman
doesn't work properly...

Code: Select all

OpenConsole()
PrintN("test")

RunProgram("cmd.exe","/k pause","")

PrintN("test")
Input()
1. the second print is executed before the wait
2. if you press enter, the console would not be closed but you will end up in the dos prompt

Posted: Sat Dec 27, 2008 5:22 am
by Mistrel
It's only useful to pause the console as it ends not while it's running.

Posted: Sat Dec 27, 2008 8:18 am
by graves

Code: Select all

OpenConsole()
print("Press any key to continue...")
input()
printn("pressed...")
input()                     ; to avoid immediate close
CloseConsole()

Posted: Sat Dec 27, 2008 12:59 pm
by Trond
graves wrote:

Code: Select all

OpenConsole()
print("Press any key to continue...")
input()
printn("pressed...")
input()                     ; to avoid immediate close
CloseConsole()
Try it with any key but enter.


This works properly.

Code: Select all

Procedure WaitAnyKey()
  While Not Inkey()
    Delay(10)
  Wend
EndProcedure


OpenConsole() 
PrintN("Press any key to continue...") 
WaitAnyKey()
PrintN("ok") 
Input()
CloseConsole()

Posted: Sat Dec 27, 2008 2:12 pm
by hallodri
try this :

Code: Select all

ImportC "msvcrt.lib"
  system(str.p-ascii)
EndImport 

OpenConsole()

system("Pause")

Posted: Sat Dec 27, 2008 2:22 pm
by AND51
Rook Zimbabwe wrote:But... but... my keyboard doesn't HAVE an ANY key!!! :wink:
Mine has this key...

Image :wink:


@ hallodri:
cmd wrote:Der Befehl "P" ist entweder falsch geschrieben oder
konnte nicht gefunden werden.
(command not found)

Posted: Sat Dec 27, 2008 2:50 pm
by hallodri
for Unicode try _wsystem(str.s)

Posted: Sat Dec 27, 2008 3:39 pm
by AND51
Sorry, I forgot that I've enabled Unicode by default. :oops:
In ASCII mode, it works.

Posted: Sat Dec 27, 2008 3:46 pm
by Kaeru Gaman
Mistrel wrote:It's only useful to pause the console as it ends not while it's running.
lolz?

nonsense!

a pause is a pause is a pause.



@hallodri

thnx!

Posted: Sat Dec 27, 2008 9:48 pm
by SFSxOI
Rook Zimbabwe wrote:But... but... my keyboard doesn't HAVE an ANY key!!! :wink:

Seriously nice idea Mistrel! :D
Thank You Mistrel :)

@ Rook Zimbabwe - I'm guessing you don't have unicode capability with your keyboard either do you? ;)

Posted: Sat Dec 27, 2008 10:04 pm
by Rook Zimbabwe
I use the UTF-Texas standard... YeeHAH!! :wink:

Nope... I don't generally use unicode!

Posted: Sun Dec 28, 2008 6:09 am
by Mistrel
hallodri wrote:try this :

Code: Select all

ImportC "msvcrt.lib"
  system(str.p-ascii)
EndImport 

OpenConsole()

system("Pause")
Thank you for this, hallodri. I was actually trying to use the same function "System" which is available in Dev-C++ for calling Pause but could not find something similar in PureBasic. This is it. :)

Posted: Sun Dec 28, 2008 9:07 am
by Rescator

Code: Select all

OpenConsole()

Print("Press enter/return to continue . . . ")
Input()

CloseConsole()
:P :twisted: