Bug 9091 - Console.KeyAvailable returns true when it shouldn't if a modifier key is pressed
Summary: Console.KeyAvailable returns true when it shouldn't if a modifier key is pressed
Status: RESOLVED FIXED
Alias: None
Product: Class Libraries
Classification: Mono
Component: mscorlib ()
Version: 2.10.x
Hardware: PC Windows
: --- normal
Target Milestone: Untriaged
Assignee: Bugzilla
URL:
Depends on:
Blocks:
 
Reported: 2012-12-20 14:30 UTC by derrickcreamer
Modified: 2013-02-04 10:52 UTC (History)
2 users (show)

Tags:
Is this bug a regression?: ---
Last known good build:

Notice (2018-05-24): bugzilla.xamarin.com is now in read-only mode.

Please join us on Visual Studio Developer Community and in the Xamarin and Mono organizations on GitHub to continue tracking issues. Bugzilla will remain available for reference in read-only mode. We will continue to work on open Bugzilla bugs, copy them to the new locations as needed for follow-up, and add the new items under Related Links.

Our sincere thanks to everyone who has contributed on this bug tracker over the years. Thanks also for your understanding as we make these adjustments and improvements for the future.


Please create a new report on GitHub or Developer Community with your current version information, steps to reproduce, and relevant error messages or log files if you are hitting an issue that looks similar to this resolved bug and you do not yet see a matching new report.

Related Links:
Status:
RESOLVED FIXED

Description derrickcreamer 2012-12-20 14:30:51 UTC
Using Mono 2.10.2 on Windows 7.

Console.KeyAvailable returns true as soon as a modifier key(ctrl, alt, or shift) is pressed. This only seems to affect Mono on Windows; on Linux it worked as expected.

When running the source code below, I expect KeyAvailable to be false until a (full) valid keypress is available - that is, a valid keypress that can be consumed by Console.ReadKey().

Instead, upon pressing CTRL, ALT, or SHIFT, I see the message indicating "KeyAvailable is true". The program then waits until I input a valid keypress that can be read by ReadKey().

The code works as expected with Mono+Linux and .NET+Windows. The problem only appears on Mono+Windows.

Source code to reproduce:

using System;
namespace KeyAvailableBugReport{
	class MainClass{
		public static void Main (string[] args){
			while(true){
				if(Console.KeyAvailable){
					Console.WriteLine("KeyAvailable is true");
					Console.ReadKey();
					break;
				}
			}
			Console.WriteLine ("Keypress registered");
		}
	}
}
Comment 1 Marek Safar 2013-02-04 10:52:17 UTC
Fixed in master