Advertisement
Guest User

rawinput.h

a guest
Oct 4th, 2015
70
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.72 KB | None | 0 0
  1. #ifndef RAWINPUT_H_
  2. #define RAWINPUT_H_
  3.  
  4. #include <windows.h>
  5. #include <detours.h> // Required for function hooking
  6.  
  7. #define RAWINPUTHDRSIZE sizeof(RAWINPUTHEADER)
  8. #define RAWPTRSIZE 40
  9. #define INPUTWINDOW "RInput"
  10.  
  11. // Prevent warning level 4 warnings for detouring
  12. #pragma warning(disable: 4100)
  13.  
  14. /**
  15. * Sadly everything has been made static, as Win32 API does not support object oriented callbacks, as it has been written in C.
  16. * To keep the performance as high as possible, I decided not to work with storing the class instance through Win32 API.
  17. * Feel free to rewrite this to something more clean in coding terms :).
  18. */
  19. class CRawInput {
  20. public:
  21. // Initialize raw input
  22. static bool initialize(WCHAR* pwszError);
  23.  
  24. // Enable/Disable the hooking
  25. static bool hookLibrary(bool bInstall);
  26.  
  27. // Hooked functions handling
  28. static int __stdcall hGetCursorPos(LPPOINT lpPoint);
  29. static int __stdcall hSetCursorPos(int x, int y);
  30.  
  31. // Poll Input
  32. static unsigned int pollInput();
  33.  
  34. // Input Window Proc
  35. static LRESULT __stdcall wpInput(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam);
  36.  
  37. // Initialization
  38. static bool initWindow(WCHAR* pwszError);
  39. static bool initInput(WCHAR* pwszError);
  40.  
  41. // Unload Raw Input
  42. static void unload();
  43.  
  44. private:
  45. static long x;
  46. static long y;
  47. static long set_x;
  48. static long set_y;
  49. // idk what to call this. getcursorpos behaves normally when s == false.
  50. // s is set to true whenever setcursorpos is called and false whenever getcursorpos is called.
  51. // this way, things work normally in 2d scenarios where setcursorpos is never called
  52. static bool s;
  53.  
  54. static HWND hwndInput;
  55. static bool bRegistered;
  56. };
  57.  
  58. extern void displayError(WCHAR* pwszError);
  59.  
  60. #endif
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement