Results 1 to 7 of 7

Thread: Key Up event wont run

  1. #1

    Thread Starter
    New Member
    Join Date
    Dec 2009
    Posts
    13

    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!

  2. #2

    Thread Starter
    New Member
    Join Date
    Dec 2009
    Posts
    13

    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?

  3. #3
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    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.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  4. #4
    INXSIVE Bruce Fox's Avatar
    Join Date
    Sep 2001
    Location
    Melbourne, Australia
    Posts
    7,429

    Re: Key Up event wont run

    I've never had issues, as long as you have 'Me.KeyPreview = True' it should work....

  5. #5
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: Key Up event wont run

    Quote Originally Posted by Bruce Fox View Post
    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.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  6. #6
    Lively Member
    Join Date
    Dec 2005
    Location
    UK
    Posts
    127

    Re: Key Up event wont run

    Quote Originally Posted by jmcilhinney View Post
    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

  7. #7
    INXSIVE Bruce Fox's Avatar
    Join Date
    Sep 2001
    Location
    Melbourne, Australia
    Posts
    7,429

    Re: Key Up event wont run

    Quote Originally Posted by jmcilhinney View Post
    .... 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
  •  



Click Here to Expand Forum to Full Width