Click here to Skip to main content
16,013,489 members
Home / Discussions / C#
   

C#

 
GeneralRe: detecting a key press... Pin
Nick Parker8-Jun-02 19:34
protectorNick Parker8-Jun-02 19:34 
GeneralRe: detecting a key press... Pin
Rama Krishna Vavilala9-Jun-02 1:03
Rama Krishna Vavilala9-Jun-02 1:03 
GeneralRe: detecting a key press... Pin
9-Jun-02 5:11
suss9-Jun-02 5:11 
GeneralRe: detecting a key press... Pin
Humpo9-Jun-02 7:24
Humpo9-Jun-02 7:24 
GeneralRe: detecting a key press... Pin
Rama Krishna Vavilala9-Jun-02 9:58
Rama Krishna Vavilala9-Jun-02 9:58 
GeneralRe: detecting a key press... Pin
Rama Krishna Vavilala9-Jun-02 10:01
Rama Krishna Vavilala9-Jun-02 10:01 
GeneralRe: detecting a key press... Pin
9-Jun-02 11:49
suss9-Jun-02 11:49 
GeneralRe: detecting a key press... Pin
Humpo9-Jun-02 12:04
Humpo9-Jun-02 12:04 
hope this helps..
class Class1
	{
		private bool bLoop;
		private Thread myThread;
		[STAThread]
		static void Main(string[] args)
		{
			Class1 c1 = new Class1();
		}

		public Class1()
		{
			bLoop = true;
			KeyReader kr = new KeyReader();	
			kr.KeyEvent += new KeyReader.KeyEvents(KeyEvent);
			myThread = new Thread(new ThreadStart(kr.ThreadRun));
			myThread.Start();
			while(bLoop)
			{
				System.Console.WriteLine(System.DateTime.Now);
			}
			myThread.Abort();// not sure if correct
		}
		
		private void KeyEvent(int k)
		{
			System.Console.WriteLine("Key Event");
			if(k=='e'|| k=='E')
				bLoop = false;
		}
	}

	public class KeyReader    
	{
		public delegate void KeyEvents(int c);  
		public event KeyEvents KeyEvent;

		public void ThreadRun( )
		{
			bool loop = true;
			while(loop)
			{
				int ch = System.Console.Read();

				if(KeyEvent != null)
				{
					System.Console.ReadLine();//remove the endline character from stream
					KeyEvent(ch);
				}
			}
		}
	}


if anyone spots errors in code, please point them out for me Smile | :)
QuestionUse \ in string? Pin
Brian Olej8-Jun-02 12:37
Brian Olej8-Jun-02 12:37 
AnswerRe: Use \ in string? Pin
James T. Johnson8-Jun-02 13:05
James T. Johnson8-Jun-02 13:05 
GeneralRe: Use \ in string? Pin
Brian Olej8-Jun-02 14:22
Brian Olej8-Jun-02 14:22 
AnswerRe: Use \ in string? Pin
Nick Parker8-Jun-02 18:43
protectorNick Parker8-Jun-02 18:43 
Questionfunction pointer in C#? Pin
Todd Smith7-Jun-02 14:36
Todd Smith7-Jun-02 14:36 
AnswerRe: function pointer in C#? Pin
James T. Johnson7-Jun-02 14:59
James T. Johnson7-Jun-02 14:59 
GeneralRe: function pointer in C#? Pin
Todd Smith7-Jun-02 15:12
Todd Smith7-Jun-02 15:12 
GeneralFile I/O Pin
7-Jun-02 13:36
suss7-Jun-02 13:36 
GeneralRe: File I/O Pin
James T. Johnson7-Jun-02 14:03
James T. Johnson7-Jun-02 14:03 
GeneralRe: File I/O Pin
Nish Nishant7-Jun-02 14:11
sitebuilderNish Nishant7-Jun-02 14:11 
GeneralRe: File I/O Pin
8-Jun-02 9:30
suss8-Jun-02 9:30 
GeneralRe: File I/O Pin
Humpo8-Jun-02 10:12
Humpo8-Jun-02 10:12 
GeneralRe: File I/O Pin
James T. Johnson8-Jun-02 10:43
James T. Johnson8-Jun-02 10:43 
GeneralRe: File I/O Pin
8-Jun-02 15:51
suss8-Jun-02 15:51 
GeneralRe: File I/O Pin
8-Jun-02 16:23
suss8-Jun-02 16:23 
GeneralRe: File I/O Pin
Humpo9-Jun-02 1:26
Humpo9-Jun-02 1:26 
GeneralI'm confused, what exactly is C# Pin
Nnamdi Onyeyiri7-Jun-02 12:58
Nnamdi Onyeyiri7-Jun-02 12:58 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.