Sunday, July 12, 2009

C# On Key Press help!?

I am new to C# and I am making an auto typer for runescape...


I want to put an event that when the user presses the Insert key, it will initiate my counter...


Any C# gurus able to help!?!?!?

C# On Key Press help!?
Hello,





If your working with GUI's (User Interfaces) you could select the control that you want to bind the "insert key" by clicking on that control, and going to the events property and choosing "Key Press". The events property is available as a yellow lightning bolt icon in the Properties window.





Once your click on the Key Press event in the properties window, the KeyPress method stub will be created for you, and you just enter the condition if e.KeyChar == (char)Keys.Insert, so if you press insert, it will trigger that part of code.





----------------


private void myControl_KeyPress(object sender, KeyPressEventArgs e)


{


if (e.KeyChar == (char)Keys.Insert)


{


// Initialize Counter ....


}


}


----------------





If your doing a Console based application, then you must use the Console.ReadKey method as well as ConsoleKeyInfo class which that method is stored....





An example of the above is available at Microsofts MSDN webpage with a detailed tutorial. It is similar to th User Interface approach but using different classes. http://msdn2.microsoft.com/en-us/library...





Good Luck.





PS: If you wish to use mulitple controls to do the Key Press, then you need to do a KeyPress for those controls as well.

gift baskets

No comments:

Post a Comment