473,386 Members | 1,830 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

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
Feb 9 '07 #1
6 1952
iburyak
1,017 Expert 512MB
Try this:

[PHP]

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


Private Sub Form_KeyDown(KeyCode 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]
Feb 9 '07 #2
Thanks a lot ^^
however i am using visual basic .net...
it seems that i cannot use ' vbkeydown' or ' vbkeyup'....
Feb 9 '07 #3
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
Feb 10 '07 #4
Killer42
8,435 Expert 8TB
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.
Feb 10 '07 #5
fiore
1
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
Mar 5 '07 #6
Killer42
8,435 Expert 8TB
...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.
Mar 5 '07 #7

Sign in to post your reply or Sign up for a free account.

Similar topics

12
by: Conrad | last post by:
Greetings, Q: Is there some way to gracefully suspend a python app for a second or so then resume? I could write the classic basic dumb loop-tenzillion-times delay, but that seems inelegant, and...
23
by: Antoon Pardon | last post by:
I have had a look at the signal module and the example and came to the conclusion that the example wont work if you try to do this in a thread. So is there a chance similar code will work in a...
4
by: Jan Danielsson | last post by:
Hello all, I have a list of servers which an application connects to. If the connection fails, the application should mark the server as temporarily unavailable, and should try to use the server...
5
by: Sargo | last post by:
Hey all, Im fairly new with C++ and i havent been able to find an answer anywhere else so far, so I'm asking here. I'm looking for a way to do a time delay. What I mean by this is where the...
0
by: bdtmike | last post by:
I'm using VS2005 and creating a VB.Net Winforms app. The app uses a couple of web services. For some reason, when I start the app, there is a 30 second delay when VB invokes its first web service....
0
by: jayasakthi | last post by:
when we freeze the columns of a table in jsp, there is a time delay in scrolling the page. when we unlock the columns the time delay is not there. is there any solution for decreasing the time...
1
by: klmishraa79 | last post by:
i want to know how i can put a time delay between two command execution...i.e. after first command of programm the second command should execute after some fixed delay......i want to use time delay...
35
by: rebeccatre | last post by:
hi can Variant archiving setTimout('.. capability be done without using it? :-)
6
by: priyajohal | last post by:
#include<fstream.h> #include<process.h> #include<stdlib.h> #include<conio.h> #include<string.h> #include<dos.h> #include<ctype.h> #include<stdio.h> void setup() void help();
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.