home features api download svn donate license send a comment contact
Spanish  
 

InputCore (pre-alpha version)

InputCore is a generic input system that lets you use any input devices such as keyboards, mouses, joysticks, etc... Written in C++, and created with the idea to helping the developers.

The source code is under the LGPL license. This means that it is completely free to use for commercial and non commercial applications.

 InputCore Logo
 
 

Example using the implementation class

This example shows how you can use the implementation class.

#include <windows.h>
// We are including the main header file it that contains
// the implementation class.

#include <ceInputCoreImpl.h>
#include <cstdio> // For printf.

// We are using the namespace "ce" (CorEngine) by default (Optional).

using namespace ce;

::HWND hWnd;

// We are creating our own manager class, inheriting the implementation class.
class CInputManager : public IInputManagerImpl<CInputManager>
{
public:

inline void Example(void) const
{
// Queries the joystick driver for the number of joysticks it supports.
std::printf("\n Joystick Supported : %i \n",
this -> Joystick -> GetNumSupported());
// Retrieves the device count.
std::printf("\n Joystick Count : %i \n",
this -> Joystick -> GetDeviceCount());
};

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

private:

// --- The keyboard event callbacks ---

// This callback is called when a key is pressed (Optional).

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

// This callback is called when a key is released (Optional).
inline void OnKeyReleased(const IKeyboardDevice *Owner,
const int key, const int buffer[256])
{ std::printf("\n KEYBOARD - OnKeyReleased : %i \n", key); };

// This callback is always called while is keep pressed any key (Optional).
inline void OnKeyEvent(const IKeyboardDevice *Owner, const int buffer[256])
{
// std::printf("\n KEYBOARD - OnKeyEvent \n");
};

// --- The mouse event callbacks ---

// This callback is called when a button is pressed (Optional).
inline void OnButtonPressed(const IMouseDevice *Owner,
const int button, const SMouseState &State)
{ std::printf("\n MOUSE - OnButtonPressed : %i \n", button); };

// This callback is called when a button is released (Optional).
inline void OnButtonReleased(const IMouseDevice *Owner,
const int button, const SMouseState &State)
{ std::printf("\n MOUSE - OnButtonReleased : %i \n", button); };

// This callback is always called, when the cursor is moved or
// while is keep pressed any button
(Optional).
inline void OnMouseEvent(
const IMouseDevice *Owner, const SMouseState &State)
{
// std::printf("\n MOUSE - OnMouseEvent \n");
};

// --- The joystick event callbacks ---

// This callback is called when a button is pressed (Optional).
inline void OnJoyButtonPressed(const IJoystickDevice *Owner,
const int joyid, const unsigned int button, const SJoystickState &State)
{ std::printf("\n JOYSTICK - OnJoyButtonPressed : %i \n", button); };

// This callback is called when a button is released (Optional).
inline void OnJoyButtonReleased(const IJoystickDevice *Owner,
const int joyid, const unsigned int button, const SJoystickState &State)
{ std::printf("\n JOYSTICK - OnJoyButtonReleased : %i \n", button); };

// This callback is always called while is keep pressed
// any button or axis
(Optional).
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)
{
// We are creating a instance of our manager class.
const CInputManager Input;

// Verify the integrity of the manager class (Optional).
if (Input -> VerifyInputManager() == 0) return 1;

Input -> Example();

// --- Create a window ---

::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);

// --- Main loop ---

::MSG msg;

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

// Update the status of all devices.
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;
}

Note : Use the implementation class, because is more easy.

 

Example using the interface class

This example shows how you can use the interface class.

#include <windows.h>
// We are including the main header file it that contains the interface class.
#include <ceInputCore.h>
#include <cstdio> // For printf.

// We are using the namespace "ce" (CorEngine) by default (Optional).

using namespace ce;

::HWND hWnd;

// We are creating our own event class, inheriting the iterface class for
// events devices.

class CInputEvent :
public IKeyboardEvent, // Interface of the keyboard event (Optional).
public IMouseEvent, // Interface of the mouse event (Optional).
public IJoystickEvent // Interface of the joystick event (Optional).
{
public:

// --- The keyboard event callbacks ---

//
This callback is called when a key is pressed.
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);
};

// This callback is called when a key is released.
inline void OnKeyReleased(const IKeyboardDevice *Owner,
const int key, const int buffer[256])
{ std::printf("\n KEYBOARD - OnKeyReleased : %i \n", key); };

// This callbak always is called, when pressing any key.
inline void OnKeyEvent(const IKeyboardDevice *Owner, const int buffer[256])
{
// std::printf("\n KEYBOARD - OnKeyEvent \n");
};

// --- The mouse event callbacks ---

//
This callback is called when a button is pressed.
inline void OnButtonPressed(const IMouseDevice *Owner,
const int button, const SMouseState &State)
{ std::printf("\n MOUSE - OnButtonPressed : %i \n", button); };

// This callback is called when a button is released.
inline void OnButtonReleased(const IMouseDevice *Owner,
const int button, const SMouseState &State)
{ std::printf("\n MOUSE - OnButtonReleased : %i \n", button); };

// This callbak always is called, when the cursor is moved or
// when pressing any button
.
inline void OnMouseEvent(
const IMouseDevice *Owner, const SMouseState &State)
{
// std::printf("\n MOUSE - OnMouseEvent \n");
};

// --- The joystick event callbacks ---

//
This callback is called when a button is pressed.
inline void OnJoyButtonPressed(const IJoystickDevice *Owner,
const int joyid, const unsigned int button, const SJoystickState &State)
{ std::printf("\n JOYSTICK - OnJoyButtonPressed : %i \n", button); };

// This callback is called when a button is released.
inline void OnJoyButtonReleased(const IJoystickDevice *Owner,
const int joyid, const unsigned int button, const SJoystickState &State)
{ std::printf("\n JOYSTICK - OnJoyButtonReleased : %i \n", button); };

// This callbak always is called, when pressing any
// button or axis
.
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)
{
// We are creating a instance of the manager class.
IInputManager *Input = CreateInputManager();
if (Input == NULL) return 1;

// Retrieves the input devices.
IKeyboardDevice *Keyboard = Input -> GetKeyboardDevice();
IMouseDevice *Mouse = Input -> GetMouseDevice();
IJoystickDevice *Joystick = Input -> GetJoystickDevice();

// Set the input events.
Keyboard -> SetKeyboardEvent(&InputEvent);
Mouse -> SetMouseEvent(&InputEvent);
Joystick -> SetJoystickEvent(&InputEvent);

// Queries the joystick driver for the number of joysticks it supports.
std::printf("\n Joystick Supported : %i \n", Joystick -> GetNumSupported());
// Retrieves the device count.
std::printf("\n Joystick Count : %i \n", Joystick -> GetDeviceCount());

// --- Create a window ---

::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);

// --- Main loop ---

::MSG msg;

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

// Update the status of all devices.
Input -> Update();
}

// Release the instance of the class 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;
}
 

So here you know the basics for their use, for more information, I recommend reading the API documentation. For support or with any questions or suggestions, feel free to contact me.

 
 
 SourceForge.net
 
   Creative Commons License   Except where otherwise noted, content on this site is
  licensed under a Creative Commons Attribution 3.0 License