Author Topic: VB.NET help  (Read 1067 times)

Offline Zeggy

  • Global Moderator
  • Level 35
  • *****
  • Posts: 1,187
  • Reputation: +13/-4
    • View Profile
VB.NET help
« on: May 06, 2007, 11:38:25 AM »
Does anybody know how to capture more than one key press at a time?
Currently I am using this code:

Code: [Select]
    Private Sub Form1_KeyDown1(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles Me.KeyDown
        If e.KeyCode = Keys.Up Then
            'do something
        ElseIf e.KeyCode = Keys.Down Then
            'do something
        ElseIf e.KeyCode = Keys.Left Then
            'do something
        ElseIf e.KeyCode = Keys.Right Then
            'do something
        End If
    End Sub

But this method only seems to capture on key press at a time. If I hold down two, only the last one is used.

Oh yeah, also, one more question: How can I set autoRedraw on? I think this was a property in VB5, but I can't find it in VB.NET!

Thanks :)

Offline Broda

  • Level 13
  • *
  • Posts: 97
  • Reputation: +2/-0
    • View Profile
    • Nightfall Games
Re: VB.NET help
« Reply #1 on: May 06, 2007, 07:58:04 PM »
I'm not sure if they have an automatic way but this is what I usually do:

Code: [Select]
Dim mv_strKeysDown As String

    Private Sub Form1_KeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles Me.KeyDown
        Dim str As String
        str = ChrW(e.KeyCode)
        If Not mv_strKeysDown Like "*" & str & "*" Then
            mv_strKeysDown &= str

        End If

        lbl.Text = mv_strKeysDown

    End Sub

    Private Sub Form1_KeyUp(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles Me.KeyUp
        mv_strKeysDown = Replace(mv_strKeysDown, ChrW(e.KeyCode), "")
        lbl.Text = mv_strKeysDown

    End Sub

    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        mv_strKeysDown = vbNullString

    End Sub


*Edit: I just tried that with the arrow keys and it doesn't work but if you used something other than chrw it probably would work...

Offline Zeggy

  • Global Moderator
  • Level 35
  • *****
  • Posts: 1,187
  • Reputation: +13/-4
    • View Profile
Re: VB.NET help
« Reply #2 on: May 07, 2007, 09:45:38 AM »
Thanks Broda :)
I found another solution on the web: http://www.vb-helper.com/howto_detect_arrow_keys.html

And now my other question :D
Quote
How can I set autoRedraw on? I think this was a property in VB5, but I can't find it in VB.NET!

Offline Broda

  • Level 13
  • *
  • Posts: 97
  • Reputation: +2/-0
    • View Profile
    • Nightfall Games
Re: VB.NET help
« Reply #3 on: May 07, 2007, 03:24:07 PM »
Thanks Broda :)
I found another solution on the web: http://www.vb-helper.com/howto_detect_arrow_keys.html

Yeah, that's basicly the same thing except that you make it array based instead of string based. Same concept though.

And now my other question :D
How can I set autoRedraw on? I think this was a property in VB5, but I can't find it in VB.NET!

http://www.vbdotnetheaven.com/UploadFile/rmeyer/AutoRedrawInVBdotNET04222005014903AM/AutoRedrawInVBdotNET.aspx?ArticleID=53317371-53bc-4b13-8c4b-46aea66e23be

 


SimplePortal 2.3.3 © 2008-2010, SimplePortal