Hi all ~! I have a question about time delay....

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • raiden1985
    New Member
    • Feb 2007
    • 5

    Hi all ~! I have a question about time delay....

    Hi all~

    I would like to ask

    I am doing a game project and i have to control a picturebox to move by pushing a Key (e.g. Keys.up)
    i used PerformClick() but there is a key delay( abt 1 sec...when you press the key, it waited abt 1 sec before it make continous movement)
    i want the picturebox move smoothly as i press the key

    How can i cancel the time delay?

    Thanks
  • iburyak
    Recognized Expert Top Contributor
    • Nov 2006
    • 1016

    #2
    Try this:

    [PHP]

    Private Sub Form_Load()
    Me.KeyPreview = True
    End Sub


    Private Sub Form_KeyDown(Ke yCode As Integer, Shift As Integer)
    If KeyCode = vbKeyUp Then Picture1.Top = Picture1.Top - 50
    If KeyCode = vbKeyDown Then Picture1.Top = Picture1.Top + 50
    End Sub[/PHP]

    Comment

    • raiden1985
      New Member
      • Feb 2007
      • 5

      #3
      Thanks a lot ^^
      however i am using visual basic .net...
      it seems that i cannot use ' vbkeydown' or ' vbkeyup'....

      Comment

      • sirsnorklingtayo
        New Member
        • Jan 2007
        • 26

        #4
        I don't know if this API is still working under VB.net because I am using this to delay some functionalities in VB6. But if there is some changes to this function you can refer to API Viewer of Visual Studio.

        'Declare this function first
        Public Declare Sub Sleep Lib "kernel32" Alias "Sleep" (ByVal dwMilliseconds As Long)

        then use it to your procedures, example

        Sleep 1000 ' wait a second then continue


        norman

        Comment

        • Killer42
          Recognized Expert Expert
          • Oct 2006
          • 8429

          #5
          Originally posted by raiden1985
          Thanks a lot ^^
          however i am using visual basic .net...
          it seems that i cannot use ' vbkeydown' or ' vbkeyup'....
          Try looking up the documentation for the event, or for SendKeys statement (if that still exists in .Net) to find the constants you want. Also, you don't actually have to use the constants - you can just use the literal value. To find out what they are, you can just put code in the KeyDown event to print the value that was received, then press your key.

          In any case, remember that the KeyDown and KeyUp events fire once when a key is pressed or released - they don't repeat. So what you would need to do is basically start looping somehow (enable a timer control, perhaps) when the KeyDown event fires for your key, and stop when KeyUp event fires.

          Comment

          • fiore
            New Member
            • Mar 2007
            • 1

            #6
            I would like to ask

            I would like to ask

            I am doing a robot project and i have to control a picturebox to move by pushing a Key (e.g. Keys.up)
            i used PerformClick() but there is no key delay( so want to create delay abt 5sec...when you press the key, it waited abt 5 sec before it make continous movement)
            i want the picturebox come out after 5 second

            How can i create the time delay after 5 second i click the key?

            Thanks

            Comment

            • Killer42
              Recognized Expert Expert
              • Oct 2006
              • 8429

              #7
              Originally posted by fiore
              ...How can i create the time delay after 5 second i click the key?
              Try reading back through this thread - time delays were already covered.

              Alternatively, try searching TheScripts (see search box at top right) for topics like "vb sleep" - it comes up fairly often. I don't want to advise too specifically, as I think it varies between versions.

              Comment

              Working...