Detecting keys in Pocket PC Game.

G

Guest

Hi

I'm writing a small Pocket PC game in C# using the .NET Compact Framework. I'm overriding the OnKeyDown and OnKeyUp methods to handle game input. The problem is that the OnKeyDown mehtod isn't executed untill i release the arrow key. That way i cant make my space ship move left/right/up/down when you're pressing (and holding) down one of the arrow keys.

Some example code of a moving sprite/object whould be greatly appreciated!
 
C

Chris Tacke, eMVP

For moving sprites, there are several great MSDN articles. Start here:

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnnetcomp/html/WrapGAPI1.asp
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnnetcomp/html/WrapGAPI2.asp
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnnetcomp/html/WrapGAPI3.asp

-Chris


Jonas Follesø said:
Hi.

I'm writing a small Pocket PC game in C# using the .NET Compact Framework.
I'm overriding the OnKeyDown and OnKeyUp methods to handle game input. The
problem is that the OnKeyDown mehtod isn't executed untill i release the
arrow key. That way i cant make my space ship move left/right/up/down when
you're pressing (and holding) down one of the arrow keys.
 
G

Guest

Hi Chris, and thanks for your reply

I've implemented the GXInput class described in the WrapGAPI3.asp article. In my game loop i do input.KeyPressed((int))Keys.Left); and print the value to the screen (it returns a bool). The problem is still the same. It will only return true for a brief second the moment i release the hardware key on the emulator. It wont return true if it's beeing pushed down.

That's my main problem: I want to move up/down/left/right when the hardware buttons is beeing pushed.
 
G

Geoff Schwab

Hi Jonas,

The GXInput class provides methods for detecting when a key is just pressed
(was not pressed on the previous frame) or the key is currently pressed
(does not care about the previous frame). I have not seen a problem with
these before so it could be a hardware or driver issue.

Can you just set a flag when true is returned by your key press method and
then not clear it until a key up is returned? Kind of a hack but I don't
know what the problem could be. If this is on the emulator then I seem to
recall some kind of bug with this.

Geoff
Jonas follesø said:
Hi Chris, and thanks for your reply!

I've implemented the GXInput class described in the WrapGAPI3.asp article.
In my game loop i do input.KeyPressed((int))Keys.Left); and print the value
to the screen (it returns a bool). The problem is still the same. It will
only return true for a brief second the moment i release the hardware key on
the emulator. It wont return true if it's beeing pushed down.
That's my main problem: I want to move up/down/left/right when the
hardware buttons is beeing pushed.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top