gbadev.org forum archive

This is a read-only mirror of the content originally found on forum.gbadev.org (now offline), salvaged from Wayback machine copies. A new forum can be found here.

OffTopic > "Key States" on the PC

#83678 - thegamefreak0134 - Wed May 17, 2006 8:42 pm

I am designing an emulator for the PC. (A cheap one, don't worry about it. It's just for practice.) Anywho, I'm doing this in VB.NET, meaning that I have to basically fight the system to get simple stuff done. Grr...

I have a timer running in the program with a delay of 1 millisecond that is processing commands. (this allows me to poll other parts of the form in-between commands to do things like, oh say, close the program.) However, since I am using this event to run the program, I am afraid I cannot get the keyDown events and similar stuff to fire at all. Is there an easy way in VB.NET to poll the states of keys? Basically, I want to be able to check (within any function) if keys are up or down. Help?

-thegamefreak0134
_________________
What if the hokey-pokey really is what it's all about?

[url=http:/www.darknovagames.com/index.php?action=recruit&clanid=1]Support Zeta on DarkNova![/url]

#83682 - kusma - Wed May 17, 2006 8:54 pm

I'm not too fluent in .NET, but i would assume that they provide some sort of GetAsyncKeyState()-replacement.

#83684 - keldon - Wed May 17, 2006 8:56 pm

There is, I just haven't done .net in a long while. But you can just respond to the key events and store values instead of polling; that way you don't have the overhead of switching between kernel/user mode.

#83685 - thegamefreak0134 - Wed May 17, 2006 9:21 pm

I tried that already. Problem is, it's never seeing the key get pressed (It's kinda hard to try to hit keys in-between other events that are running all the time) the event to poll the keys never fires.
_________________
What if the hokey-pokey really is what it's all about?

[url=http:/www.darknovagames.com/index.php?action=recruit&clanid=1]Support Zeta on DarkNova![/url]

#83688 - keldon - Wed May 17, 2006 9:41 pm

WM_KEYDOWN. Not sure what it's called in .net

http://www.google.co.uk/search?q=.net+keydown&start=0&ie=utf-8&oe=utf-8

Read this >> http://bdn.borland.com/article/0,1410,30129,00.html

There is also a method (I remember) that will get you a set of states at one time; but it is often best to respond to events.

#83689 - zzo38computer - Wed May 17, 2006 9:48 pm

Maybe you need to use DirectX
_________________
Important: Please send messages about FWNITRO to the public forum, not privately to me.

#83697 - Joe_Sextus - Wed May 17, 2006 10:19 pm

I've never used VB.NET, but couldn't you use a class with a static structure to hold the keystate and have event delegates update it.

Just a thought.

-Joe

#83839 - naleksiev - Thu May 18, 2006 9:57 pm

hohoho. I hate VB but I'll try to help.

I can't give you the code because I stoped writing in VB ... 4 years ago and I do not have VB.NET installed (btw I will suggest you if you like .NET just start learning C# - if you have experiance with VB and you know the C++ syntax it will take 2 days :))

About the problem: You suppost to use form so you can use the form events. VB.NET support 2 ways to handle an event. You can use the old style like we made this in VB6 or just adding the handler into the KeyDown event - the event is actualy somethink like an array, so you can add or remove the handlers. The other way is just to override the OnKeyDown method. So using one of the previews tehniks just store the key in some array with bools for example and turn the flag off if you have OnKeyUp. Now you can use this array to check when ever you want is some key pressed.

About this timer on 1 millisecond :( it's too small delay do you think so?

#83843 - keldon - Thu May 18, 2006 10:47 pm

Or you can use the information in the link I gave you ( http://bdn.borland.com/article/0,1410,30129,00.html )