Input

Started by
1 comment, last by tomalak 11 years, 9 months ago
I’m trying to port some C#/xna code into vc++/direct. I’m struggling with keyboard and mouse input yet again. I hope you can offer some suggestions. I’m not going to write a test case because the problem pertains to how input is handled in WinAPI etc.

My problem is the way the C# code handles keyboard and mouse input. As you can see by the C# code below, KeyboardInput provides the functionality for handling key releases and mouse down, mouse up and mouse move.

http://ideone.com/TO4rl

It uses syntax like this:

MouseInput.MouseDown += new MouseClickHandler(MouseInput_MouseDown);

I’m not sure what’s happening with this code but I assume that when somebody clicks the Mouse Down then the MouseInput_MouseDown() function is being called.

If you compare this to how I’ve been laying it out in c++.

http://ideone.com/Cbjw5

http://ideone.com/VMGHd

As you can see, each down and up of a key or mouse button has its own bool. And then I’m performing logic depending on the state of these bools. But i’m finding that there is too many of them, and I never know where to reset the state of them. I’m posting the state of these bools from main here:

http://ideone.com/g3Q1B

My main issue is that my update method is going to become too cluttered. And using this method is very slow progress. One thing i’ve considered is separating out the triggering of each event into different methods but update is being called repeatedly and I only want certain functions to be called if a given set of conditions is met (if a key is pressed or released).

So where do you think i’m going wrong and how can I change it for the better. Oh, I realise that Logans XNA code has types for handling input (MouseInput and KeyboardInput). These are built into xna. I’m assuming it has overrides for the += but i’m reaching the limit of my understanding just saying that and have no idea what I’m doing.

So is there a library of code built into vc++/directx to help me handle this. Is there a lib I can install and use, or do I have to write something to handle this myself.

I’m kind of answering my own questions as I write this which is why it is good to post questions on forums. It helps you understand your own problem better.

--
Wisey
Advertisement
Somebody in irc said that there's no replies because this is a boring topic field. But i'm quite stuck with this problem. Please help. I understand that it might be my c++ skills that are lacking.

--
Wisey

Somebody in irc said that there's no replies because this is a boring topic field.


No, there are no replies because:

I’m not going to write a test case[/quote]

And because:

I’m kind of answering my own questions as I write this which is why it is good to post questions on forums[/quote]

is wrong. Write your questions out in a private area if you haven't finished working through the problem. Then post a specific, precise question relating only to what you still do not understand. People don't have spare time to donate for decoding your thought processes!

This topic is closed to new replies.

Advertisement