Tuesday, January 21, 2014

Input System Update 3 - Keyboard Working!

Hello Again,

I'm here to announce today that the keyboard part of the input system is now live and working! As I said on the last post, I'm postponing the messaging system, but I am yet to decide how to handle this. So, I am now focusing on the callback approach, where you register a function to be called when a pattern is matched. As of now, the only accepted function form is void(*)(). This means that the function should be void with no arguments (like void setJump(); ).

All of our system's parts are finished for keyboard input, and it is enough to show you how exactly it is supposed to be used, and give you a good idea on what to expect for mouse and thumbstick.

Basically, the keyboard has two possible actions: key up and key down. But mouses and thumbsticks also have movement. This movement adds a whole new complexity to them. It will need to pass along more information, like the pointer position when a click happened. This makes me question the viability of using the same approach I did with the keyboard. The problem is that those controls are special and should be managed as such... I'll probably make a simplified interpreter that could be used to get simple actions (such as single or double clicks) and maybe some specific movement gestures like shaking the pointer. On top of that, the program should still have a pointer to the controller object of the mouse, so it could easily get the pointer position. Of course, an indirect interface for this kind of thing is necessary, in case this controller pointer is no longer on scope or for safer code where you only want to interact with the interpreter.

Back to the keyboard, It is done and functional. Not field-tested, but tested to some extent. This is an example code of how to use the entire system, from the start to the update(); :

This code shows the usage of all the classes mentioned on the last post: GestureInterpreter, Pattern, BasicInput.
This code will detect whenever the escape key is pressed or the W is released and will exit by using the callback. It will also answer with a console output whenever the user hit the ASD keys in sequence within the configured time limits.

The link to download the source code is here: Download. The example contained inside is different, as it tests for slightly more complex patterns (that would not embed the blog very well).
Note: forgive me for the code itself, I will clean it up before anything else, and, specially, separate the useful files from the ones that are still useless.

My planned next steps are:
  • Add gamepad support (no thumbstick here);
  • Create a showcase for this system allowing for Gamepad and Keyboard (minigame);
  • Add as much support for mouse and thumbsticks interpretation as viable;
  • Create the interface to allow a more direct access to both mouse and thumbs.
In the future:
  • Add the polling and messaging systems to the interpreter;
  • Create a Lua interface, so this can be done on a higher (and less wordy) level; and probably
  • add a way to read the event log externally.

I also want to say that if any of you have any feedback it will be appreciated. Thank you all who already sent me messages with suggestions and comments!

Over and Out.

No comments:

Post a Comment