Visual Basic 2008 KeyDown Delay? [RESOLVED]

Whether you're a newbie or an experienced programmer, any questions, help, or just talk of any language will be welcomed here.

Moderator: Coders of Rage

Post Reply
User avatar
Exiled
Chaos Rift Newbie
Chaos Rift Newbie
Posts: 28
Joined: Sat Feb 19, 2011 11:34 am
Current Project: Zenoa
Favorite Gaming Platforms: N64, GC, NES
Programming Language of Choice: VB08
Contact:

Visual Basic 2008 KeyDown Delay? [RESOLVED]

Post by Exiled »

Hey everybody, I've been doing Visual Basic game development for about 7 months now. I've never actually tried making an RPG style game before, but now I am attempting to accomplish it. I've always used the KeyDown event for checking if a key is pressed to move your character. However, when you do hold a key down, it responds as if in a text program... It sends the key once, waits, then continues going. I would like to remove this delay within the program, but nowhere else. I would also like to remove it without having to change the user's settings. Any help will be appreciated. Thanks!
Last edited by Exiled on Sun Feb 20, 2011 11:17 pm, edited 1 time in total.
http://www.overlordgaming.tk

"If you can't find something to live for, you best find something to die for."
User avatar
Ginto8
ES Beta Backer
ES Beta Backer
Posts: 1064
Joined: Tue Jan 06, 2009 4:12 pm
Programming Language of Choice: C/C++, Java

Re: Visual Basic 2008 KeyDown Delay?

Post by Ginto8 »

What you should do is have to subs that handle KeyDown and KeyUp events respectively, and some sort of structure/class for holding key states, then have those 2 subs update the keystates, and have a timer-activated sub that uses them. At least that's how I do it.

Also, check out KeyPress events. I'm not sure, but they seem more likely to have key repeat than KeyDown events.
Quit procrastinating and make something awesome.
Ducky wrote:Give a man some wood, he'll be warm for the night. Put him on fire and he'll be warm for the rest of his life.
User avatar
Exiled
Chaos Rift Newbie
Chaos Rift Newbie
Posts: 28
Joined: Sat Feb 19, 2011 11:34 am
Current Project: Zenoa
Favorite Gaming Platforms: N64, GC, NES
Programming Language of Choice: VB08
Contact:

Re: Visual Basic 2008 KeyDown Delay?

Post by Exiled »

That's pretty much what I do. But I'm talking about the delay when you hold the key down. I might just not understand exactly what you said. And I've attempted to work with KeyPress but I couldn't find a working solution to execute the same code that my KeyDown event does.
http://www.overlordgaming.tk

"If you can't find something to live for, you best find something to die for."
User avatar
Ginto8
ES Beta Backer
ES Beta Backer
Posts: 1064
Joined: Tue Jan 06, 2009 4:12 pm
Programming Language of Choice: C/C++, Java

Re: Visual Basic 2008 KeyDown Delay?

Post by Ginto8 »

well if you control the key state something like this:

Code: Select all

private sub onDown(...) handles KeyDown
   state.<key> = true 
end sub

private sub onUp(...) handles KeyUp
   state.<key> = false
end sub
then it should reliably tell you when a certain key is currently being pressed. You can take advantage of this in a sub that handles a Timer.Tick event:

Code: Select all

private withevents t as Timer
sub New()
    t = new Timer(...)
    t.start()
end sub
private sub frameLogic() handles t.Tick
    ' do stuff
end sub
Quit procrastinating and make something awesome.
Ducky wrote:Give a man some wood, he'll be warm for the night. Put him on fire and he'll be warm for the rest of his life.
User avatar
Exiled
Chaos Rift Newbie
Chaos Rift Newbie
Posts: 28
Joined: Sat Feb 19, 2011 11:34 am
Current Project: Zenoa
Favorite Gaming Platforms: N64, GC, NES
Programming Language of Choice: VB08
Contact:

Re: Visual Basic 2008 KeyDown Delay?

Post by Exiled »

I haven't attempted it yet, but will it remove the delay and tell me if the key is being pressed or held down?
http://www.overlordgaming.tk

"If you can't find something to live for, you best find something to die for."
User avatar
Exiled
Chaos Rift Newbie
Chaos Rift Newbie
Posts: 28
Joined: Sat Feb 19, 2011 11:34 am
Current Project: Zenoa
Favorite Gaming Platforms: N64, GC, NES
Programming Language of Choice: VB08
Contact:

Re: Visual Basic 2008 KeyDown Delay?

Post by Exiled »

Hm... When I executed the code, it produced the same delay..
http://www.overlordgaming.tk

"If you can't find something to live for, you best find something to die for."
User avatar
Ginto8
ES Beta Backer
ES Beta Backer
Posts: 1064
Joined: Tue Jan 06, 2009 4:12 pm
Programming Language of Choice: C/C++, Java

Re: Visual Basic 2008 KeyDown Delay?

Post by Ginto8 »

it shouldn't produce a delay if you actually have some sort of way of storing the state and you use other subs (read: not onDown and onUp) to check the key states for different things. If you keep using onDown and onUp for logic, there will be a delay.
Quit procrastinating and make something awesome.
Ducky wrote:Give a man some wood, he'll be warm for the night. Put him on fire and he'll be warm for the rest of his life.
User avatar
Exiled
Chaos Rift Newbie
Chaos Rift Newbie
Posts: 28
Joined: Sat Feb 19, 2011 11:34 am
Current Project: Zenoa
Favorite Gaming Platforms: N64, GC, NES
Programming Language of Choice: VB08
Contact:

Re: Visual Basic 2008 KeyDown Delay?

Post by Exiled »

Ah, I modified the code a little bit and it worked! Thanks :D
http://www.overlordgaming.tk

"If you can't find something to live for, you best find something to die for."
Post Reply