| View previous topic :: View next topic |
| Author |
Message |
Stylo Grandmaster Cheater Supreme
Reputation: 3
Joined: 16 May 2007 Posts: 1073 Location: Israel
|
Posted: Sat Nov 10, 2007 4:08 am Post subject: [request] a command in C# |
|
|
i'm looking for the command that makes that nometter what key i press it exits from the console window you know.. like "press any key to continue" and nometter what key u press it exits.. is there a command for that thing in C#? _________________
Stylo |
|
| Back to top |
|
 |
atom0s Moderator
Reputation: 205
Joined: 25 Jan 2006 Posts: 8587 Location: 127.0.0.1
|
|
| Back to top |
|
 |
Stylo Grandmaster Cheater Supreme
Reputation: 3
Joined: 16 May 2007 Posts: 1073 Location: Israel
|
Posted: Sat Nov 10, 2007 7:29 am Post subject: |
|
|
the console.readline that's what i use right now but it's not what i was looking for cuz if i press 'X' for exemple it's not exit the console window it writes X in the console window and after i press enter it exits
i want to enter X and it exit out of the window without pressing enter after _________________
Stylo |
|
| Back to top |
|
 |
atom0s Moderator
Reputation: 205
Joined: 25 Jan 2006 Posts: 8587 Location: 127.0.0.1
|
Posted: Sat Nov 10, 2007 8:26 am Post subject: |
|
|
| 1qaz wrote: | the console.readline that's what i use right now but it's not what i was looking for cuz if i press 'X' for exemple it's not exit the console window it writes X in the console window and after i press enter it exits
i want to enter X and it exit out of the window without pressing enter after |
I don't program in C# so I'm not sure on it, I looked it up on MSDN and according to Microsoft, thats how it should be done.
In any case, try importing _getch() instead, that should do the trick. _________________
- Retired. |
|
| Back to top |
|
 |
Stylo Grandmaster Cheater Supreme
Reputation: 3
Joined: 16 May 2007 Posts: 1073 Location: Israel
|
Posted: Sat Nov 10, 2007 8:47 am Post subject: |
|
|
can u give me the whole command please cuz when i write import / ing gatch() it says compiling error _________________
Stylo |
|
| Back to top |
|
 |
lurc Grandmaster Cheater Supreme
Reputation: 2
Joined: 13 Nov 2006 Posts: 1900
|
Posted: Sat Nov 10, 2007 9:40 am Post subject: |
|
|
im pretty sure you just import conio.h (i think thats the header)
| Code: | #include <conio.h>
blablablah coding
_getch();
|
_________________
|
|
| Back to top |
|
 |
samuri25404 Grandmaster Cheater
Reputation: 7
Joined: 04 May 2007 Posts: 955 Location: Why do you care?
|
Posted: Sat Nov 10, 2007 9:51 am Post subject: |
|
|
He's talking about C#, not C++.
Try this:
| Code: |
Console.WriteLine("Press any key to continue.");
Console.Read();
|
|
|
| Back to top |
|
 |
atom0s Moderator
Reputation: 205
Joined: 25 Jan 2006 Posts: 8587 Location: 127.0.0.1
|
Posted: Sat Nov 10, 2007 11:10 am Post subject: |
|
|
| 1qaz wrote: | | can u give me the whole command please cuz when i write import / ing gatch() it says compiling error |
Check the demo project out on the link I gave you above, it shows how to import it and use it. (Again, I don't program in C# so I can't make one myself.) _________________
- Retired. |
|
| Back to top |
|
 |
Stylo Grandmaster Cheater Supreme
Reputation: 3
Joined: 16 May 2007 Posts: 1073 Location: Israel
|
Posted: Sat Nov 10, 2007 11:50 am Post subject: |
|
|
i have problem with sighning up to this website S:
can any1 upload this demo please? _________________
Stylo |
|
| Back to top |
|
 |
atom0s Moderator
Reputation: 205
Joined: 25 Jan 2006 Posts: 8587 Location: 127.0.0.1
|
Posted: Sat Nov 10, 2007 11:54 am Post subject: |
|
|
Sure. _________________
- Retired. |
|
| Back to top |
|
 |
samuri25404 Grandmaster Cheater
Reputation: 7
Joined: 04 May 2007 Posts: 955 Location: Why do you care?
|
Posted: Sat Nov 10, 2007 12:47 pm Post subject: |
|
|
If you wanna use getCh(), then so be it:
| Code: |
[DllImport("msvcrt.dll")]
public static extern int _getch();
|
Later on in your code:
| Code: |
Console.WriteLine("Press any key to continue...");
_getch();
|
That simple.
I would just prefer to have as little DLL Imports in a project as I can.
Edit:
Or if you actually want to get the char, and not pause it:
| Code: |
char c = (char)_getch();
|
_getch() returns an int, so when you cast it as a character, it returns an actual character. |
|
| Back to top |
|
 |
Lord._ Grandmaster Cheater Supreme
Reputation: 0
Joined: 13 Jan 2007 Posts: 1169 Location: iFun Story Owner
|
Posted: Sat Nov 10, 2007 1:07 pm Post subject: |
|
|
o.O Try this... (I don't really understand but if you click a button and it exit...)
Using System;
Console.WriteLine("Press any key to continue");
Console.ReadLine();
Environment(0).Exit();
Something like that... |
|
| Back to top |
|
 |
killersamurai Expert Cheater
Reputation: 0
Joined: 10 Sep 2007 Posts: 197 Location: Colorado
|
Posted: Sat Nov 10, 2007 1:54 pm Post subject: |
|
|
| Console.ReadKey(); is what you would want. This command is like read or readline but once a key is pressed, it will exit instead of waiting for someone to press enter. |
|
| Back to top |
|
 |
samuri25404 Grandmaster Cheater
Reputation: 7
Joined: 04 May 2007 Posts: 955 Location: Why do you care?
|
Posted: Sat Nov 10, 2007 6:02 pm Post subject: |
|
|
| killersamurai wrote: | | Console.ReadKey(); is what you would want. This command is like read or readline but once a key is pressed, it will exit instead of waiting for someone to press enter. |
What's the difference between that and Console.Read(); ? |
|
| Back to top |
|
 |
killersamurai Expert Cheater
Reputation: 0
Joined: 10 Sep 2007 Posts: 197 Location: Colorado
|
Posted: Sat Nov 10, 2007 6:22 pm Post subject: |
|
|
It gets the key pressed by the user and then displays it. If you don't want the key to be shown on the console, just put false.
| Code: |
Console.ReadKey(true);
|
|
|
| Back to top |
|
 |
|