InputCore es un sistema de entrada
genérico que le permite utilizar
cualquier dispositivo de entrada como teclados, ratones, joysticks,
etc... Escrito en
C++ y creado con la idea de ayudar a los desarrolladores.
El
código fuente esta bajo licencia LGPL. Esto quiere decir que
es
completamente libre para utilizarlo en aplicaciones comerciales y no
comerciales.
Ejemplo utilizando la clase
implementación
Este ejemplo muestra como puedes utilizar la clase
implementación.
#include <windows.h> // Incluimos el archivo de cabecera principal, que contiene // la clase implementacion. #include <ceInputCoreImpl.h> #include <cstdio> // Por printf.
// Utilizamos el namespace "ce" (CorEngine) por defecto (Opcional). using namespace ce;
::HWND hWnd;
// Creamos nuestra propia clase manager, heredando la clase implementacion. class CInputManager : public IInputManagerImpl<CInputManager> { public:
inline void Example(void) const { // Consultamos al driver del joystick por el numero de joysticks // que este mismo soporta. std::printf("\n Joystick Supported : %i \n", this -> Joystick -> GetNumSupported()); // Recibimos la cantidad de joysticks conectados. std::printf("\n Joystick Count : %i \n", this -> Joystick -> GetDeviceCount()); };
// Este callback es llamado cuando se presiona una tecla (Opcional). inline void OnKeyPressed(const IKeyboardDevice *Owner, const int key, const int buffer[256]) { std::printf("\n KEYBOARD - OnKeyPressed : %i \n", key); if (key == KEY_ESCAPE) ::DestroyWindow(hWnd); };
// Este callback es llamado cuando se suelta una tecla (Opcional). inline void OnKeyReleased(const IKeyboardDevice *Owner, const int key, const int buffer[256]) { std::printf("\n KEYBOARD - OnKeyReleased : %i \n", key); };
// Este callback siempre es llamado mientras se mantenga // cualquier tecla presiona (Opcional). inline void OnKeyEvent(const IKeyboardDevice *Owner, const int buffer[256]) { // std::printf("\n KEYBOARD - OnKeyEvent \n"); };
// --- Los callbacks de eventos del mouse ---
// Este callback es llamado cuando se presiona un boton (Opcional). inline void OnButtonPressed(const IMouseDevice *Owner, const int button, const SMouseState &State) { std::printf("\n MOUSE - OnButtonPressed : %i \n", button); };
// Este callback es llamado cuando se suelta un boton (Opcional). inline void OnButtonReleased(const IMouseDevice *Owner, const int button, const SMouseState &State) { std::printf("\n MOUSE - OnButtonReleased : %i \n", button); };
// Este callback siempre es llamado cuando se mueve el cursor o // se mantenga cualquier boton presionado (Opcional). inline void OnMouseEvent( const IMouseDevice *Owner, const SMouseState &State) { // std::printf("\n MOUSE - OnMouseEvent \n"); };
// --- Los callbacks de eventos del joystick ---
// Este callback es llamado cuando se presiona un boton (Opcional). inline void OnJoyButtonPressed(const IJoystickDevice *Owner, const int joyid, const unsigned int button, const SJoystickState &State) { std::printf("\n JOYSTICK - OnJoyButtonPressed : %i \n", button); };
// Este callback es llamado cuando se suelta un boton (Opcional). inline void OnJoyButtonReleased(const IJoystickDevice *Owner, const int joyid, const unsigned int button, const SJoystickState &State) { std::printf("\n JOYSTICK - OnJoyButtonReleased : %i \n", button); };
// Este callback siempre es llamado mientras se mantenga cualquier // eje o boton presionado (Opcional). inline void OnJoystickEvent(const IJoystickDevice *Owner, const int joyid, const SJoystickState &State) { // std::printf("\n JOYSTICK - OnJoystickEvent \n"); };
Nota : Utiliza la clase
implementación, porque es mas fácil.
Ejemplo utilizando las clases de interfaces
Este ejemplo muestra como puedes utilizar las
clases de interfaces.
#include <windows.h> // Incluimos el archivo de cabecera principal, que contiene la clase interfaz. #include <ceInputCore.h> #include <cstdio> // Por printf.
// Utilizamos el namespace "ce" (CorEngine) por defecto (Opcional). using namespace ce;
::HWND hWnd;
// Creamos nuestra propia clase de eventos, heredando las clases de interfaces // de los eventos de los dispositivos de entrada. class CInputEvent : public IKeyboardEvent, // Interfaz de eventos del teclado (Opcional). public IMouseEvent, // Interfaz de eventos del mouse (Opcional). public IJoystickEvent // Interfaz de eventos del joystick (Opcional). { public:
// --- Los callbacks de eventos del teclado ---
// Este callback es llamado cuando se presiona una tecla. inline void OnKeyPressed(const IKeyboardDevice *Owner, const int key, const int buffer[256]) { std::printf("\n KEYBOARD - OnKeyPressed : %i \n", key); if (key == KEY_ESCAPE) ::DestroyWindow(hWnd); };
// Este callback es llamado cuando se suelta una tecla. inline void OnKeyReleased(const IKeyboardDevice *Owner, const int key, const int buffer[256]) { std::printf("\n KEYBOARD - OnKeyReleased : %i \n", key); };
// Este callback siempre es llamado mientras se mantenga // cualquier tecla presiona. inline void OnKeyEvent(const IKeyboardDevice *Owner, const int buffer[256]) { // std::printf("\n KEYBOARD - OnKeyEvent \n"); };
// --- Los callbacks de eventos del mouse ---
// Este callback es llamado cuando se presiona un boton. inline void OnButtonPressed(const IMouseDevice *Owner, const int button, const SMouseState &State) { std::printf("\n MOUSE - OnButtonPressed : %i \n", button); };
// Este callback es llamado cuando se suelta un boton. inline void OnButtonReleased(const IMouseDevice *Owner, const int button, const SMouseState &State) { std::printf("\n MOUSE - OnButtonReleased : %i \n", button); };
// Este callback siempre es llamado cuando se mueve el cursor o // se mantenga cualquier boton presionado. inline void OnMouseEvent( const IMouseDevice *Owner, const SMouseState &State) { // std::printf("\n MOUSE - OnMouseEvent \n"); };
// --- Los callbacks de eventos del joystick ---
// Este callback es llamado cuando se presiona un boton. inline void OnJoyButtonPressed(const IJoystickDevice *Owner, const int joyid, const unsigned int button, const SJoystickState &State) { std::printf("\n JOYSTICK - OnJoyButtonPressed : %i \n", button); };
// Este callback es llamado cuando se suelta un boton. inline void OnJoyButtonReleased(const IJoystickDevice *Owner, const int joyid, const unsigned int button, const SJoystickState &State) { std::printf("\n JOYSTICK - OnJoyButtonReleased : %i \n", button); };
// Este callback siempre es llamado mientras se mantenga cualquier // eje o boton presionado. inline void OnJoystickEvent(const IJoystickDevice *Owner, const int joyid, const SJoystickState &State) { // std::printf("\n JOYSTICK - OnJoystickEvent \n"); };
int main(int argc, char **argv) { // Creamos una instancia de la clase manager. IInputManager *Input = CreateInputManager(); if (Input == NULL) return 1;
// Establecemos los eventos de entrada. Keyboard -> SetKeyboardEvent(&InputEvent); Mouse -> SetMouseEvent(&InputEvent); Joystick -> SetJoystickEvent(&InputEvent);
// Consultamos al driver del joystick por el numero de joysticks // que este mismo soporta. std::printf("\n Joystick Supported : %i \n", Joystick -> GetNumSupported()); // Recibimos la cantidad de joysticks conectados. std::printf("\n Joystick Count : %i \n", Joystick -> GetDeviceCount());
Hasta aquí ya sabes lo básico
para su utilización,
para mas información, recomiendo leer la documentación
de la API. Para
soporte o ante cualquier duda o sugerencia, no dudes en contactarme.