epicglottis
New member
- Joined
- Apr 2, 2005
- Messages
- 2
- Programming Experience
- 1-3
Hello, I discovered the free beta version of VB express 2005 and am trying to become familiar with VS .NET by developing a simple tetris clone.
I have had no problems until I tried to process keyboard input.
All the googling I have done result in the same code which does not work.
(i.e. if e.KeyCode == Keys.Right Then ...)
My question is this: is there a property which enables all the keys to be processed at a form level, or am I not handling the keydown event properly, or something else?
(Short: Why doesn't the commented code work?)
Here is my current code:
Note: oddly enough all the keys work except the arrow keys and enter when I enable the "Key Preview" form property. (the code below works, however I would like to use the commented code instead)
-Thanks in advance!
I have had no problems until I tried to process keyboard input.
All the googling I have done result in the same code which does not work.
(i.e. if e.KeyCode == Keys.Right Then ...)
My question is this: is there a property which enables all the keys to be processed at a form level, or am I not handling the keydown event properly, or something else?
(Short: Why doesn't the commented code work?)
Here is my current code:
VB.NET:
Private Sub Form1_KeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles Me.KeyDown
Select Case e.KeyCode
Case Keys.D 'case Keys.Right
CurrentBlock.Right()
Case Keys.A 'Case Keys.Left
CurrentBlock.Left()
Case Keys.W 'Case Keys.Up
CurrentBlock.Rotate()
Case Keys.S 'Case Keys.Down
CurrentBlock.Down()
End Select
End Sub
Note: oddly enough all the keys work except the arrow keys and enter when I enable the "Key Preview" form property. (the code below works, however I would like to use the commented code instead)
-Thanks in advance!
Last edited: