
[Input] : Detect a new keypress and a constant key press
Posted Wednesday, 28 October, 2009 - 08:26 by iliak| Project: | The Open Toolkit library |
| Version: | all versions |
| Component: | Code |
| Category: | support request |
| Priority: | normal |
| Assigned: | Unassigned |
| Status: | by design |
Jump to:
Description
It's a nice (not to say important feature) to detect the difference between a new key press (just pressed key) and a constant key press (key down for several frames) events. You can have a look here to know how I handle the case. The main idea is to poll keyboard state at each frame and store the previous / current states in an array. To detect a constant key press, both value in the array are true, and to detect a new keypress, only the current array is true, and the previous is false.
You can extented this technique for more input device (mouse and gamepad).


Comments
#1
This has been requested a few times in the past. The situation is as follows:
The solution is trivial: have the user compare states and find their differences:
I was thinking about reusing the event-based interface (KeyboardDevice) to simplify this process, but I don't think I can implement this in time for OpenTK 1.0.