I need to be able to determine how long a key has been held down with high accuracy. For example if they key tapped really fast it could report a time that is less than the time for each update frame.
|
|
You could capture the input by using the System.Windows.Forms.NativeWindow class. You'll get a notification when an input event occurs. That way you'll be notified as fast as possible right when it occurs, letting you record the time to a higher precision. It gets kind of messy (native/unsafe code), but it works. I think this only works on windows, but I think that's the platform your targeting (no need for this on Xbox and WP7). Here is a good example (from nuclex framework): WindowInputCapturer (note: this code might have been updated recently and I didn't code it) Edit: This also allows you to get at the character code of the key press. This could be useful for taking text input (especially things like latin characters) I'm not sure why you would need to get input at such a high precision, but this would be a good way to do it in my opinion. |
||||
|
|
|
XNA is a looped based framework, not an event based framework. If you need the exact time an event occurred, consider a winforms project (an event based project) and connect XNA to a control if necessary for rendering. |
|||
|
|
|
Store key state into a variable and compare on the next loop to current key states. Create a Very simple example of what I mean:
|
|||||||||
|
|
I'm not aware of any official way of doing this, you could run a second thread in a very tight loop just to check the input and send this of to a circular buffer sufficiently large to require very little synchronization between threads. (Store some kind of increasing number in each slot of the buffer and update that AFTER the thread wrote all the data, then continue reading slots with data from the buffer until the number decreases (don't forget to check for overflowing numbers!)) |
|||
|
|
|
If you update thirty times per second, a human will not be able to press keys faster than you can sample the keyboard state. If you update more slowly than a human can type, then you may need one thread for rendering graphics, and another thread for reading and responding to the keyboard / mouse. But, if you update more slowly than a human can type, then you can't provide visual feedback for each key press either. This doesn't matter if the idea is to display aggregate feedback, such as average time between key presses. |
|||||||||||
|
