|
-
Mar 17th, 2010, 05:03 PM
#1
Thread Starter
New Member
Key Up event wont run
Hey, am making a tetris game in VB its all working now apart from the keyboard events to move and rotate the blocks, which is the most important part 0_0
I have this to deal with keyboard input. But it dose nothing whats wrong with this code?
Code:
Private Sub mainForm_KeyUp(ByVal sender As System.Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles MyBase.KeyDown
Select Case e.KeyCode
Case Keys.Down
Me.player1.MoveDown()
Case Keys.Left
Me.player1.MoveLeft()
Case Keys.Right
Me.player1.MoveRight()
Case Keys.P
Me.player1.IsPaused = Not Me.player1.IsPaused
Case Keys.Up
Me.player1.ToggleOrientation()
End Select
End Sub
Thanks!
-
Mar 17th, 2010, 05:07 PM
#2
Thread Starter
New Member
Re: Key Up event wont run
Got it working now, however arrow keys wont work.
I changed the arrow key downs to w,a,s,d and it now works.
why might this be?
-
Mar 17th, 2010, 06:58 PM
#3
Re: Key Up event wont run
The arrow keys are special and are treated differently to other keys. I think you have to override the IsInputKey method of a control to get it to treat the arrows like other keys, although I've never tried so I'm not sure.
-
Mar 17th, 2010, 07:05 PM
#4
Re: Key Up event wont run
I've never had issues, as long as you have 'Me.KeyPreview = True' it should work....
-
Mar 17th, 2010, 07:17 PM
#5
Re: Key Up event wont run
 Originally Posted by Bruce Fox
I've never had issues, as long as you have 'Me.KeyPreview = True' it should work....
Hmmm... I thought that the arrow keys were treated differently in certain circumstances but I just tested and, when Buttons have focus at least, the arrow keys are registered by KeyUp as normal. Assuming KeyPreview is True, I'd be interested to know what controls have focus in the OP's project.
-
Mar 17th, 2010, 08:17 PM
#6
Lively Member
Re: Key Up event wont run
 Originally Posted by jmcilhinney
Hmmm... I thought that the arrow keys were treated differently in certain circumstances but I just tested and, when Buttons have focus at least, the arrow keys are registered by KeyUp as normal. Assuming KeyPreview is True, I'd be interested to know what controls have focus in the OP's project.
they are in some instances ... i remember this was also the case in vb6
-
Mar 17th, 2010, 08:27 PM
#7
Re: Key Up event wont run
 Originally Posted by jmcilhinney
.... I'd be interested to know what controls have focus in the OP's project.
Thats where it becomes interesting, as it usually is that last thing that your made aware of (as you'd know) 
In any case, in this example I suspect the OP doesn't have the Forms KeyPreview set as the OP stated that nothing happened.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|