Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #pragma once
- #ifndef INPUT_H
- #define INPUT_H
- #define WIN32_LEAN_AND_MEAN
- #include <d3d9.h>
- #include <Windows.h>
- #include <windowsx.h>
- #include <string>
- #include "ERROR.h"
- #include <Xinput.h>
- #ifndef HID_USAGE_PAGE_GENERIC
- #define HID_USAGE_PAGE_GENERIC ((USHORT) 0x01)
- #endif
- #ifndef HID_USAGE_GENERIC_MOUSE
- #define HID_USAGE_GENERIC_MOUSE ((USHORT) 0x02)
- #endif
- namespace InputNS
- {
- const int KEYS_ARRAY_LENGTH = 256;
- const UCHAR KEYS_DOWN = 1;
- const UCHAR KEYS_PRESSED = 2;
- const UCHAR MOUSE = 4;
- const UCHAR TEXT_IN = 8;
- const UCHAR KEYS_MOUSE_TEXT = KEYS_DOWN + KEYS_PRESSED + MOUSE + TEXT_IN;
- }
- const short GAMEPAD_THUMBSTICK_DEADZONE = (short)(0.20f * 0X7FFF);
- const short GAMEPAD_TRIGGER_DEADZONE = 20;
- const DWORD MAX_CONTROLLERS = 4;
- const DWORD GAMEPAD_DPAD_UP = 0x0001;
- const DWORD GAMEPAD_DPAD_DOWN = 0x0002;
- const DWORD GAMEPAD_DPAD_LEFT = 0x0004;
- const DWORD GAMEPAD_DPAD_RIGHT = 0x0008;
- const DWORD GAMEPAD_START_BUTTON = 0x0010;
- const DWORD GAMEPAD_BACK_BUTTON = 0x0020;
- const DWORD GAMEPAD_LEFT_THUMB = 0x0040;
- const DWORD GAMEPAD_RIGHT_THUMB = 0x0080;
- const DWORD GAMEPAD_LEFT_SHOULDER = 0x0100;
- const DWORD GAMEPAD_RIGHT_SHOULDER = 0x0200;
- const DWORD GAMEPAD_A = 0x1000;
- const DWORD GAMEPAD_B = 0x2000;
- const DWORD GAMEPAD_X = 0x4000;
- const DWORD GAMEPAD_Y = 0x8000;
- struct ControllerState
- {
- XINPUT_STATE state;
- XINPUT_VIBRATION vibration;
- float vibrateTimeLeft;
- float vibrateTimeRight;
- bool connected;
- };
- class Input
- {
- bool _keyDown[InputNS::KEYS_ARRAY_LENGTH];
- bool _keyPressed[InputNS::KEYS_ARRAY_LENGTH];
- std::string _textIn;
- char _charIn;
- bool _newLine;
- int _mouseX;
- int _mouseY;
- int _mouseRawX;
- int _mouseRawY;
- RAWINPUTDEVICE _rid[1];
- bool _mouseCaptured;
- bool _mouseLeftButton;
- bool _mouseRightButton;
- bool _mouseMiddleButton;
- bool _mouseX1Button;
- bool _mouseX2Button;
- ControllerState _controllerState[MAX_CONTROLLERS];
- short _thumbstickDeadzone;
- short _triggerDeadzone;
- public:
- Input();
- ~Input();
- void checkControllers();
- void initialize(HWND hwnd, bool capture);
- //key input
- void keyDown(WPARAM w);
- void keyUp(WPARAM w);
- void keyIn(WPARAM w);
- bool isKeyDown(UCHAR w) const;
- bool wasKeyPressed(UCHAR w) const;
- bool anyKeyPressed() const;
- std::string getTextIn() { return _textIn; }
- char getCharIn() { return _charIn; }
- void clearKeyPress(UCHAR w);
- void clearTextIn() { _textIn.clear(); }
- void clearAll();
- void clear(UCHAR what);
- //mouse input
- void mouseIn(LPARAM l);
- void mouseRawIn(LPARAM l);
- void setMouseLeftButton(bool b) { _mouseLeftButton = b; }
- void setMouseRightButton(bool b) { _mouseRightButton = b; }
- void setMouseMiddleButton(bool b) { _mouseMiddleButton = b; }
- void setMouseXButton(WPARAM w) { _mouseX1Button = (w & MK_XBUTTON1) ? true : false; _mouseX2Button = (w & MK_XBUTTON2) ? true : false; }
- int getMouseX() const { return _mouseX; }
- int getMouseY() const { return _mouseY; }
- int getMouseRawX() const { return _mouseRawX; }
- int getMouseRawY() const { return _mouseRawY; }
- bool getMouseLeftButton() const { return _mouseLeftButton; }
- bool getMouseRightButton() const { return _mouseRightButton; }
- bool getMouseMiddleButton() const { return _mouseMiddleButton; }
- bool getMouseX1() const { return _mouseX1Button; }
- bool getMouseX2() const { return _mouseX2Button; }
- //game pad controller
- void readController();
- const ControllerState* getControllerState(UINT n);
- const WORD getGamepadButtons(UINT n);
- bool getGamepadDPadUp(UINT n);
- bool getGamepadDPadDown(UINT n);
- bool getGamepadDPadLeft(UINT n);
- bool getGamepadDPadRight(UINT n);
- bool getGamepadStart(UINT n);
- bool getGamepadBack(UINT n);
- bool getGamepadLeftThumb(UINT n);
- bool getGamepadRightThumb(UINT n);
- bool getGamepadLeftShoulder(UINT n);
- bool getGamepadRightShoulder(UINT n);
- bool getGamepadA(UINT n);
- bool getGamepadB(UINT n);
- bool getGamepadX(UINT n);
- bool getGamepadY(UINT n);
- //Gamepad Left
- BYTE getGamepadLeftTrigger(UINT n);
- BYTE getGamepadLeftTriggerUndead(UINT n);
- SHORT getGamepadThumbLX(UINT n);
- SHORT getGamepadThumbLXUndead(UINT n);
- SHORT getGamepadThumbLY(UINT n);
- SHORT getGamepadThumbLYUndead(UINT n);
- void gamePadVibrateLeft(UINT n, WORD speed, float sec);
- //Gamepad right
- BYTE getGamepadRightTrigger(UINT n);
- BYTE getGamepadRightTriggerUndead(UINT n);
- SHORT getGamepadThumbRX(UINT n);
- SHORT getGamepadThumbRXUndead(UINT n);
- SHORT getGamepadThumbRY(UINT n);
- SHORT getGamepadThumbRYUndead(UINT n);
- void gamePadVibrateRight(UINT n, WORD speed, float sec);
- //
- void vibrateControllers(float frameTime);
- };
- #endif // !INPUT_H
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement