LiveWire Peer Support Network

Printable Version of Topic "C# KeyPresses"

- LiveWire Teen Forums & College Forums (http://www.golivewire.com)
-- (http://www.golivewire.com/forums/support-technical.html)
--- Programming & Application Development (http://www.golivewire.com/forums/forum-211-s-0.html)
---- C# KeyPresses (http://www.golivewire.com/forums/peer-sbasta-support-a.html)


-- Posted by obvious Troll at 5:38 pm on Dec. 5, 2007

I'm making Tetris. The thing is, I've gotten all the hit detections and shit working. Now the next thing to do is to set it to move on a mouse button. Since we are getting ready for a Java AP test, we are not allowed to use any form designers. I've put in this code form Form1_Load:

Code:
this.KeyDown += new System.Windows.Forms.KeyEventHandler(Steering);

Code:
private void Steering(object sender, KeyEventArgs e)
       {
           Console.WriteLine("KeyData: " + e.KeyData);
           Console.WriteLine("KeyCode: " + e.KeyCode);
           Console.WriteLine("KeyValue: " + e.KeyValue);
       }

In the function Steering, on Key Press it's supposed to echo in the console the key data. However, nothing occurs when I press a key. I'm assuming what I'm doing wrong is that the buttons, that act as the tetris blocks, are being active and not the form. Any ideas to fix?


-- Posted by obvious Troll at 6:07 am on Dec. 7, 2007

Problem solved, please lock.

In case anyone experiences the same problem, on FormX_Load (or any other place where the form loses commitment), place this:
Code:
this.Activate();


www.golivewire.com