Questions tagged [console.readkey]

52 questions
1
vote
0 answers

Readkey on attached console c#

I have an application that behaves as a windows forms and as a console application depending if I pass parameters or not. If I pass parameters it behaves as a console application. In this last case, as a console application, I attach to the console…
Willy
  • 9,848
  • 22
  • 141
  • 284
1
vote
2 answers

Can I bypass Console.ReadKey() issue when input is redirected?

I am a C# teacher and I wrote some automated HW checker for my students. The students write C# Console Applications. My HW checker is based on input redirection so I can test their code on my own generated input. The problem is that students…
user2795947
  • 53
  • 1
  • 5
1
vote
2 answers

C# console app: how to prevent user from holding down a key when using a ReadKey() loop?

I'm writing a console app in C#, which reads user input using Console.ReadKey(). It has code that's similar to this: while(true) { switch(Console.ReadKey(true).Key) { case ConsoleKey.Enter: //code case…
gardenapple
  • 146
  • 1
  • 12
1
vote
2 answers

Preventing queing/preloading a character in the console before Console.ReadKey()

When Console.ReadKey(true) is called in .NET, it reads a single keypress from the user into the console. I have noticed that a character can be typed before Console.ReadKey() is actually called, allowing a user to preload a character press before…
Kyle Williamson
  • 2,251
  • 6
  • 43
  • 75
1
vote
1 answer

C++ how to read a key without waiting for key grip "Enter" on Linux and Windows

Personally, I think the title is clear, if not, I’ll try to be more. Only managed solutions for Windows, for Linux does not. As you well know, the method "getchar()" reads only after keyboard key grip "Enter". The conio.h library does not exist on…
rplaurindo
  • 1,277
  • 14
  • 23
1
vote
1 answer

c# console snake gets stuck on long key press

I just started learning programming couple months ago and decided to do a console snake game. Everything works great expect for one thing. If my snake is going upwards and I press down arrow and keep it pressed, my snake just stops and stays…
Ville
  • 13
  • 1
  • 3
1
vote
1 answer

I'm having trouble with the values which are returned by Console.ReadKey()

Here's my original code, which I was trying to modify to limit data entry to a single char, converted to uppercase. public char promptForGuess() { Console.Write("\nGuess a letter: "); return…
dwwilson66
  • 6,806
  • 27
  • 72
  • 117
1
vote
1 answer

How to get the first character

First of all, Console.ReadKey() is not the answer. I need to be able to erase the first character I write. Basically, what I'm trying to do is an application that measures your typing speed. It works perfectly, but I'm trying to work out the…
user123
  • 8,970
  • 2
  • 31
  • 52
0
votes
0 answers

How to unit test code that calls Console.ReadKey without mocking

I know I can call Console.SetIn() and pass in a StringReader. When I call Console.ReadLine() it works as expected and returns the string from the StringReader but here's the question: Is there a way to get Console.ReadKey() to behave similarly and…
LorneCash
  • 1,446
  • 2
  • 16
  • 30
0
votes
1 answer

Simple Snake Game - Snake Head is not moving after ReadKey()

The snake head 0 does not move anywhere when Console.ReadKey() happens. Here is the full code: using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace…
0
votes
1 answer

Make user press specific key to progress in program

I am currently working on a little lottery console game and wanted to add a "Working" mechanic. I created a new method and want to add multiple tasks where you have to press a specific key like the space bar for example multiple times. So something…
cloudified
  • 13
  • 5
0
votes
2 answers

How do I add to my int variables when I press a key?

The title summed up what I am trying to figure out. I am trying to get my int variables to increase and/or decrease depending on what directional key I press. int x; int y; x = 0; y = 0; Console.WriteLine("X:" +x + "Y:" +y); while…
0
votes
0 answers

VB.Net VS2019 - Problem reading in console

I request your help to be able to read these symbols in the windows console. Imports System.Text Module Module1 Sub Main() Dim userInput = New StringBuilder() Dim maxLength = 10 While True ' Read, but don't…
0
votes
3 answers

Is there a way to get a timestamp of a keystroke in C#?

I'm trying to make a simple stopwatch for a C# class I'm taking. I've googled around all afternoon and found a lot of info that I either don't understand or doesn't quite deal with the problem I'm having. As I'm currently learning about classes,…
0
votes
0 answers

Why line ConsoleKey key = Console.ReadKey().Key deletes oldest "O" on Console screen?

Trying to make snake game. I am using Console.SetCursorPosition(int x, int y) to draw body parts("O"), 2D array to store "O" previous locations and Console.KeyAvailable to detect direction changes. When a key is pressed that is not in the switch…
hasanovs
  • 33
  • 2