Advertisement
Guest User

Io.cpp

a guest
Apr 19th, 2019
114
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 3.67 KB | None | 0 0
  1. #include "Io.h"
  2.  
  3.  
  4. namespace ulib
  5. {
  6.  
  7.     namespace io {
  8.  
  9.         // GetMsg
  10.         const msg GetMsg()
  11.         {
  12.             msg data;
  13.             std::cin >> data;
  14.  
  15.             return data;
  16.         }
  17.  
  18.  
  19.  
  20.  
  21.         // SendMsg
  22.         void SendMsg(const msg& to_send)
  23.         {
  24.             std::cout << to_send;
  25.         }
  26.  
  27.         // SendMsg - Overload
  28.         void SendMsg(const msg_vector to_send)
  29.         {
  30.             for (auto& mesg : to_send)
  31.                 std::cout << mesg;
  32.         }
  33.  
  34.  
  35.         // SendSound
  36.         void SendSound(const file_path& sound_file_path)
  37.         {
  38.             const std::string command = "play " + sound_file_path;
  39.             mciSendString(command.c_str(), NULL, 0, NULL);
  40.         }
  41.  
  42.  
  43.  
  44.  
  45.         // CheckKey
  46.         const bool CheckKey(const key_code& to_check)
  47.         {
  48.             if (GetAsyncKeyState(to_check) & 0x8000)
  49.             {
  50.                 FlushConsoleInputBuffer(GetStdHandle(STD_INPUT_HANDLE));
  51.                 return true;
  52.             }
  53.  
  54.             return false;
  55.         }
  56.  
  57.  
  58.  
  59.  
  60.         // MakeKey
  61.         key MakeKey(const key_code&)
  62.         {
  63.             key temp;
  64.             return temp;
  65.         }
  66.  
  67.  
  68.         // MakeKeyCode
  69.         key_code MakeKeyCode(const int&)
  70.         {
  71.             key_code temp = 0x30;
  72.             return temp;
  73.         }
  74.  
  75.  
  76.  
  77.  
  78.         // PressKey
  79.         void PressKey(const key& to_press)
  80.         {
  81.             HoldKey(to_press);
  82.             ReleaseKey(to_press);
  83.         }
  84.  
  85.         // PressKey - Overload
  86.         void PressKey(const key_code& to_press, const time_ms& before, const time_ms& during, const time_ms& after)
  87.         {
  88.             INPUT ip;
  89.             ip.type = INPUT_KEYBOARD;
  90.             ip.ki.wScan = 0;
  91.             ip.ki.time = 0;
  92.             ip.ki.dwExtraInfo = 0;
  93.  
  94.             ip.ki.wVk = to_press;
  95.             ip.ki.dwFlags = 0;
  96.             SendInput(1, &ip, sizeof(INPUT));
  97.  
  98.             ip.ki.dwFlags = KEYEVENTF_KEYUP;
  99.             SendInput(1, &ip, sizeof(INPUT));
  100.  
  101.         }
  102.  
  103.  
  104.  
  105.  
  106.         // HoldKey
  107.         void HoldKey(const key& to_hold)
  108.         {
  109.             Sleep(to_hold.before);
  110.             Input input(to_hold.code, KEYBOARD, KEYPRESS);
  111.             Sleep(to_hold.after);
  112.         }
  113.  
  114.         // HoldKey - Overload
  115.         void HoldKey(const key_code& to_hold, const time_ms& before, const time_ms& after)
  116.         {
  117.             Sleep(before);
  118.  
  119.             INPUT ip;
  120.             ip.type = INPUT_KEYBOARD;
  121.             ip.ki.wScan = 0;
  122.             ip.ki.time = 0;
  123.             ip.ki.dwExtraInfo = 0;
  124.             ip.ki.wVk = to_hold;
  125.             ip.ki.dwFlags = 0;
  126.             SendInput(1, &ip, sizeof(INPUT));
  127.  
  128.             Sleep(after);
  129.         }
  130.  
  131.  
  132.  
  133.  
  134.         // ReleaseKey
  135.         void ReleaseKey(const key& to_release)
  136.         {
  137.             Input input(to_release.code, KEYBOARD, KEYRELEASE);
  138.             Sleep(to_release.after);
  139.         }
  140.  
  141.         // ReleaseKey - Overload
  142.         void ReleaseKey(const key_code& to_release, const time_ms& after)
  143.         {
  144.             INPUT ip;
  145.             ip.type = INPUT_KEYBOARD;
  146.             ip.ki.wScan = 0;
  147.             ip.ki.time = 0;
  148.             ip.ki.dwExtraInfo = 0;
  149.             ip.ki.wVk = to_release;
  150.             ip.ki.dwFlags = KEYEVENTF_KEYUP;
  151.             SendInput(1, &ip, sizeof(INPUT));
  152.  
  153.             Sleep(after);
  154.         }
  155.  
  156.  
  157.         // RightClick
  158.         void RightClick(const time_ms& sleep_after)
  159.         {
  160.             INPUT Input = { 0 };
  161.             Input.type = INPUT_MOUSE;
  162.             Input.mi.dwFlags = MOUSEEVENTF_RIGHTDOWN;
  163.             ::SendInput(1, &Input, sizeof(INPUT));
  164.  
  165.             ::ZeroMemory(&Input, sizeof(INPUT));
  166.             Input.type = INPUT_MOUSE;
  167.             Input.mi.dwFlags = MOUSEEVENTF_RIGHTUP;
  168.             ::SendInput(1, &Input, sizeof(INPUT));
  169.  
  170.             Sleep(sleep_after);
  171.         }
  172.  
  173.         // LeftClick
  174.         void LeftClick(const time_ms& sleep_after)
  175.         {
  176.             INPUT Input = { 0 };
  177.             Input.type = INPUT_MOUSE;
  178.             Input.mi.dwFlags = MOUSEEVENTF_LEFTDOWN;
  179.             ::SendInput(1, &Input, sizeof(INPUT));
  180.  
  181.             ::ZeroMemory(&Input, sizeof(INPUT));
  182.             Input.type = INPUT_MOUSE;
  183.             Input.mi.dwFlags = MOUSEEVENTF_LEFTUP;
  184.             ::SendInput(1, &Input, sizeof(INPUT));
  185.  
  186.             Sleep(sleep_after);
  187.         }
  188.  
  189.  
  190.         // SetCursor
  191.         void SetCursorPosition(const position& cursor_pos)
  192.         {
  193.             SetCursorPos(cursor_pos.first, cursor_pos.second);
  194.         }
  195.  
  196.  
  197.         // GetCursor
  198.         const position GetCursorPosition()
  199.         {
  200.             POINT cursor;
  201.             GetCursorPos(&cursor);
  202.  
  203.             position cursor_pos{ cursor.x, cursor.y };
  204.             return cursor_pos;
  205.         }
  206.  
  207.     }
  208.  
  209.  
  210. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement