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

Share your advanced PureBasic knowledge/code with the community.
Mistrel
Addict
Addict
Posts: 3415
Joined: Sat Jun 30, 2007 8:04 pm

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

Post by Mistrel »

Code: Select all

RunProgram("cmd.exe","/k pause","")
End
:)
User avatar
Rook Zimbabwe
Addict
Addict
Posts: 4322
Joined: Tue Jan 02, 2007 8:16 pm
Location: Cypress TX
Contact:

Post by Rook Zimbabwe »

But... but... my keyboard doesn't HAVE an ANY key!!! :wink:

Seriously nice idea Mistrel! :D
Binarily speaking... it takes 10 to Tango!!!

Image
http://www.bluemesapc.com/
User avatar
Kaeru Gaman
Addict
Addict
Posts: 4826
Joined: Sun Mar 19, 2006 1:57 pm
Location: Germany

Post 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
oh... and have a nice day.
Mistrel
Addict
Addict
Posts: 3415
Joined: Sat Jun 30, 2007 8:04 pm

Post by Mistrel »

It's only useful to pause the console as it ends not while it's running.
User avatar
graves
Enthusiast
Enthusiast
Posts: 160
Joined: Wed Oct 03, 2007 2:38 pm
Location: To the deal with a pepper

Post by graves »

Code: Select all

OpenConsole()
print("Press any key to continue...")
input()
printn("pressed...")
input()                     ; to avoid immediate close
CloseConsole()
Trond
Always Here
Always Here
Posts: 7446
Joined: Mon Sep 22, 2003 6:45 pm
Location: Norway

Post 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()
User avatar
hallodri
Enthusiast
Enthusiast
Posts: 208
Joined: Tue Nov 08, 2005 7:59 am
Location: Germany
Contact:

Post by hallodri »

try this :

Code: Select all

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

OpenConsole()

system("Pause")
Last edited by hallodri on Sat Dec 27, 2008 2:47 pm, edited 1 time in total.
AND51
Addict
Addict
Posts: 1040
Joined: Sun Oct 15, 2006 8:56 pm
Location: Germany
Contact:

Post 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)
PB 4.30

Code: Select all

onErrorGoto(?Fred)
User avatar
hallodri
Enthusiast
Enthusiast
Posts: 208
Joined: Tue Nov 08, 2005 7:59 am
Location: Germany
Contact:

Post by hallodri »

for Unicode try _wsystem(str.s)
AND51
Addict
Addict
Posts: 1040
Joined: Sun Oct 15, 2006 8:56 pm
Location: Germany
Contact:

Post by AND51 »

Sorry, I forgot that I've enabled Unicode by default. :oops:
In ASCII mode, it works.
PB 4.30

Code: Select all

onErrorGoto(?Fred)
User avatar
Kaeru Gaman
Addict
Addict
Posts: 4826
Joined: Sun Mar 19, 2006 1:57 pm
Location: Germany

Post 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!
oh... and have a nice day.
SFSxOI
Addict
Addict
Posts: 2970
Joined: Sat Dec 31, 2005 5:24 pm
Location: Where ya would never look.....

Post 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? ;)
User avatar
Rook Zimbabwe
Addict
Addict
Posts: 4322
Joined: Tue Jan 02, 2007 8:16 pm
Location: Cypress TX
Contact:

Post by Rook Zimbabwe »

I use the UTF-Texas standard... YeeHAH!! :wink:

Nope... I don't generally use unicode!
Binarily speaking... it takes 10 to Tango!!!

Image
http://www.bluemesapc.com/
Mistrel
Addict
Addict
Posts: 3415
Joined: Sat Jun 30, 2007 8:04 pm

Post 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. :)
User avatar
Rescator
Addict
Addict
Posts: 1769
Joined: Sat Feb 19, 2005 5:05 pm
Location: Norway

Post by Rescator »

Code: Select all

OpenConsole()

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

CloseConsole()
:P :twisted:
Post Reply