|
|
||||||||||||||||||||
![]() |
|||||||||||||||||||||
InputCore API Documentationpre-alpha version![]() IntroductionWelcome to the Main API Documentation for InputCore. The source code is released under the LGPL license, meaning it is free for you to use in your projects, even if they are commercial. Of course, we suggest you read the full text of the license by looking at the local LICENSE file or ceInputCore.h. LinksNamespaces: Central namespace for this entire library. A good place to begin looking. Example using the implementation classThis 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 classThis 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.
|
|||||||||||||||||||||
|