Advertisement
Guest User

Io.h

a guest
Apr 19th, 2019
111
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.06 KB | None | 0 0
  1. #pragma once
  2. #include <string>
  3. #include <vector>
  4. #include <utility>
  5. #include <iostream>
  6.  
  7. #include <Windows.h>
  8. #pragma comment(lib, "winmm.lib")
  9.  
  10.  
  11. namespace ulib
  12. {
  13.  
  14.     namespace io
  15.     {
  16.         using time_ms = double;
  17.         using position = std::pair<int, int>;
  18.         using file_path = std::string;
  19.         using msg = std::string;
  20.         using key_code = unsigned short;
  21.         using msg_vector = std::vector<msg>;
  22.  
  23.  
  24.         enum input_type
  25.         {
  26.             KEYBOARD = INPUT_KEYBOARD,
  27.             MOUSE = INPUT_MOUSE,
  28.         };
  29.  
  30.         enum input_mode
  31.         {
  32.             KEYRELEASE = 0,
  33.             KEYPRESS = KEYEVENTF_KEYUP,
  34.             MOUSEPRESSLEFT = MOUSEEVENTF_LEFTDOWN,
  35.             MOUSEPRESSRIGHT = MOUSEEVENTF_RIGHTDOWN,
  36.             MOUSERELEASELEFT = MOUSEEVENTF_LEFTUP,
  37.             MOUSERELEASERIGHT = MOUSEEVENTF_RIGHTUP,
  38.         };
  39.  
  40.         enum sleep_modes
  41.         {
  42.             PREV = 0,
  43.             CURR = 1,
  44.             NEXT = 2,
  45.         };
  46.  
  47.  
  48.         struct key
  49.         {
  50.             key_code code;
  51.             time_ms before = 0, during = 0, after = 0;
  52.             input_mode mode;
  53.         };
  54.  
  55.  
  56.         struct Input
  57.         {
  58.             INPUT input_struct;
  59.  
  60.             Input(const key_code& code, const input_type& type, const input_mode& mode)
  61.             {
  62.                 INPUT ip;
  63.                 ip.type = type;
  64.                 ip.ki.wScan = 0;
  65.                 ip.ki.time = 0;
  66.                 ip.ki.dwExtraInfo = 0;
  67.                 ip.ki.wVk = code;
  68.                 ip.ki.dwFlags = mode;
  69.  
  70.                 SendInput(1, &ip, sizeof(INPUT));
  71.             }
  72.         };
  73.  
  74.  
  75.  
  76.  
  77.         const msg GetMsg();
  78.  
  79.         const bool CheckKey(const key_code&);
  80.        
  81.         key MakeKey(const key_code&);
  82.        
  83.         key_code MakeKeyCode(const int&);
  84.        
  85.         void SetCursorPosition(const position&);
  86.        
  87.         const position GetCursorPosition();
  88.        
  89.  
  90.         void SendMsg(const msg& to_send);
  91.         void SendMsg(const msg_vector to_send);
  92.  
  93.         void SendSound(const file_path&);
  94.  
  95.  
  96.         void PressKey(const key&);
  97.         void PressKey(const key_code&, const time_ms& = 0, const time_ms& = 20, const time_ms& = 20);
  98.  
  99.         void HoldKey(const key&);
  100.         void HoldKey(const key_code&, const time_ms& = 20, const time_ms& = 20);
  101.  
  102.         void ReleaseKey(const key&);
  103.         void ReleaseKey(const key_code& = 20, const time_ms& = 20);
  104.  
  105.         void RightClick(const time_ms& = 20);
  106.         void LeftClick(const time_ms& = 20);
  107.     }
  108.     using namespace io;
  109.  
  110. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement