View Single Post
Old 01-09-2009, 03:05 PM   #5 (permalink)
Baez
Baez's Avatar
 

Join Date: Sep 2005

Location: Toronto, Canada

Posts: 5,479

Baez is a glorious beacon of lightBaez is a glorious beacon of lightBaez is a glorious beacon of lightBaez is a glorious beacon of lightBaez is a glorious beacon of light

Default Re: C#, kbhit & getch

You can use Interop to call _kbhit. The version of kbhit without the underscore is actually depricated. Make sure you use STAThread to ensure everything is synchronized; both COM and Windows objects.

Code:
using System;
using System.Runtime.InteropServices;

public class Win32Interop
{
   [DllImport("crtdll.dll")]
   public static extern int _kbhit();
}

class KBHIT
{
   [STAThread]
   static void Main(string[] args)
   {
      System.Console.WriteLine( "Press any key: " );
      while(!Win32Interop._kbhit());
   }
}

__________________


Last edited by Baez; 01-09-2009 at 03:08 PM.
Baez is offline