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.
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()); };
// 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"); };
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"); };
int main(int argc, char **argv) { // We are creating a instance of the manager class. IInputManager *Input = CreateInputManager(); if (Input == NULL) return 1;
// 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());
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.