inicio características api download svn licencia contactar
English  
 

InputCore (versión pre-alfa)

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.

 InputCore Logo
 
 

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());
};

// Operator -> (Optional).
const CInputManager* operator -> (void) const
{ return this; };

private:

// --- Los callbacks de eventos del teclado ---

// 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");
};

};

::LRESULT CALLBACK WindowProcedure(::HWND, ::UINT, ::WPARAM, ::LPARAM);

int main(int argc, char **argv)
{
// Creamos una instancia de nuestra clase manager.
const CInputManager Input;

// Verificamos la integridad de la clase manager (Opcional).
if (Input -> VerifyInputManager() == 0) return 1;

Input -> Example();

// --- Creamos una ventana ---

::WNDCLASSEX wincl;
::ZeroMemory(&wincl, sizeof(::WNDCLASSEX));

wincl.cbSize = sizeof(::WNDCLASSEX);
wincl.hInstance = ::GetModuleHandle(NULL);
wincl.lpszClassName = "InputCoreApp";
wincl.hbrBackground = (::HBRUSH) COLOR_BACKGROUND;
wincl.lpfnWndProc = WindowProcedure;

if (!::RegisterClassEx(&wincl)) return 1;

hWnd = ::CreateWindowEx(0, wincl.lpszClassName, "InputCore Example",
WS_OVERLAPPEDWINDOW, CW_USEDEFAULT, CW_USEDEFAULT, 320, 200,
HWND_DESKTOP, NULL, wincl.hInstance, NULL);

::ShowWindow(hWnd, SW_SHOWDEFAULT);

// --- Bucle principal ---

::MSG msg;

while (msg.message != WM_QUIT)
{
if (::PeekMessage(&msg, NULL, 0, 0, PM_REMOVE))
{
::TranslateMessage(&msg);
::DispatchMessage(&msg);
}

// Actualizamos el estado de todos los dispositivos.
Input -> Update();
}

::UnregisterClass(wincl.lpszClassName, wincl.hInstance);

return 0;
}

::LRESULT CALLBACK
WindowProcedure(::HWND hWnd, ::UINT message, ::WPARAM wParam, ::LPARAM lParam)
{
switch (message)
{
case WM_DESTROY: ::PostQuitMessage(0); break;
default: return ::DefWindowProc(hWnd, message, wParam, lParam);
} return 0;
}

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");
};

} InputEvent;

::LRESULT CALLBACK WindowProcedure(::HWND, ::UINT, ::WPARAM, ::LPARAM);

int main(int argc, char **argv)
{
// Creamos una instancia de la clase manager.
IInputManager *Input = CreateInputManager();
if (Input == NULL) return 1;

// Recibimos los dispositivos de entrada.
IKeyboardDevice *Keyboard = Input -> GetKeyboardDevice();
IMouseDevice *Mouse = Input -> GetMouseDevice();
IJoystickDevice *Joystick = Input -> GetJoystickDevice();

// 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());

// --- Creamos una ventana ---

::WNDCLASSEX wincl;
::ZeroMemory(&wincl, sizeof(::WNDCLASSEX));

wincl.cbSize = sizeof(::WNDCLASSEX);
wincl.hInstance = ::GetModuleHandle(NULL);
wincl.lpszClassName = "InputCoreApp";
wincl.hbrBackground = (::HBRUSH) COLOR_BACKGROUND;
wincl.lpfnWndProc = WindowProcedure;

if (!::RegisterClassEx(&wincl)) return 1;

hWnd = ::CreateWindowEx(0, wincl.lpszClassName, "InputCore Example",
WS_OVERLAPPEDWINDOW, CW_USEDEFAULT, CW_USEDEFAULT, 320, 200,
HWND_DESKTOP, NULL, wincl.hInstance, NULL);

::ShowWindow(hWnd, SW_SHOWDEFAULT);

// --- Bucle principal ---

::MSG msg;

while (msg.message != WM_QUIT)
{
if (::PeekMessage(&msg, NULL, 0, 0, PM_REMOVE))
{
::TranslateMessage(&msg);
::DispatchMessage(&msg);
}

// Actualizamos el estado de todos los dispositivos.
Input -> Update();
}

// Liberamos la instancia de la clase manager.
DestroyInputManager(&Input);

::UnregisterClass(wincl.lpszClassName, wincl.hInstance);

return 0;
}

::LRESULT CALLBACK
WindowProcedure(::HWND hWnd, ::UINT message, ::WPARAM wParam, ::LPARAM lParam)
{
switch (message)
{
case WM_DESTROY: ::PostQuitMessage(0); break;
default: return ::DefWindowProc(hWnd, message, wParam, lParam);
} return 0;
}
 

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.

 
 
 SourceForge.net
 
   Creative Commons License   Salvo que se indique lo contrario, el contenido de este sitio
  está bajo una licencia Creative Commons Attribution 3.0 License