C
C#•8mo ago
Kapa._

Press enter only

I want to code a loop which only takes spacebar for the code to loop. E.g. While (true) { Console.ReadKey(" ") loop... } However, this isint working.
12 Replies
maxmahem
maxmahem•8mo ago
mtreit
mtreit•8mo ago
That code won't compile, did you look at the documentation for ReadKey? You want something like:
while (true)
{
var key = Console.ReadKey();
if (key.KeyChar == ' ')
{
Console.WriteLine("😎");
}
}
while (true)
{
var key = Console.ReadKey();
if (key.KeyChar == ' ')
{
Console.WriteLine("😎");
}
}
Kapa._
Kapa._OP•8mo ago
huh let me try that rq you my friend r a genius i have one question tho
Kapa._
Kapa._OP•8mo ago
No description
Kapa._
Kapa._OP•8mo ago
No description
Kapa._
Kapa._OP•8mo ago
the code now inputs a space before every 'dice' and it wasnt doing that before anything i did? @mtreit or what could i change if i wanted it to be enter instead nevermind im being stupid about the spaceing before the dice lol
mtreit
mtreit•8mo ago
If you want to check for the Enter key being pressed you can do:
while (true)
{
var key = Console.ReadKey();
if (key.Key == ConsoleKey.Enter)
{
Console.WriteLine("😎");
}
}
while (true)
{
var key = Console.ReadKey();
if (key.Key == ConsoleKey.Enter)
{
Console.WriteLine("😎");
}
}
Kapa._
Kapa._OP•8mo ago
sweet stuff man ty so much
mtreit
mtreit•8mo ago
@Kapa._ BTW you might want to pass true to Console.ReadKey. That will prevent the keypresses from being printed to the screen.
Kapa._
Kapa._OP•8mo ago
you are brilliant, ty so much man
Denis
Denis•8mo ago
$close
MODiX
MODiX•8mo ago
Use the /close command to mark a forum thread as answered
Want results from more Discord servers?
Add your server