Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include "Io.h"
- namespace ulib
- {
- namespace io {
- // GetMsg
- const msg GetMsg()
- {
- msg data;
- std::cin >> data;
- return data;
- }
- // SendMsg
- void SendMsg(const msg& to_send)
- {
- std::cout << to_send;
- }
- // SendMsg - Overload
- void SendMsg(const msg_vector to_send)
- {
- for (auto& mesg : to_send)
- std::cout << mesg;
- }
- // SendSound
- void SendSound(const file_path& sound_file_path)
- {
- const std::string command = "play " + sound_file_path;
- mciSendString(command.c_str(), NULL, 0, NULL);
- }
- // CheckKey
- const bool CheckKey(const key_code& to_check)
- {
- if (GetAsyncKeyState(to_check) & 0x8000)
- {
- FlushConsoleInputBuffer(GetStdHandle(STD_INPUT_HANDLE));
- return true;
- }
- return false;
- }
- // MakeKey
- key MakeKey(const key_code&)
- {
- key temp;
- return temp;
- }
- // MakeKeyCode
- key_code MakeKeyCode(const int&)
- {
- key_code temp = 0x30;
- return temp;
- }
- // PressKey
- void PressKey(const key& to_press)
- {
- HoldKey(to_press);
- ReleaseKey(to_press);
- }
- // PressKey - Overload
- void PressKey(const key_code& to_press, const time_ms& before, const time_ms& during, const time_ms& after)
- {
- INPUT ip;
- ip.type = INPUT_KEYBOARD;
- ip.ki.wScan = 0;
- ip.ki.time = 0;
- ip.ki.dwExtraInfo = 0;
- ip.ki.wVk = to_press;
- ip.ki.dwFlags = 0;
- SendInput(1, &ip, sizeof(INPUT));
- ip.ki.dwFlags = KEYEVENTF_KEYUP;
- SendInput(1, &ip, sizeof(INPUT));
- }
- // HoldKey
- void HoldKey(const key& to_hold)
- {
- Sleep(to_hold.before);
- Input input(to_hold.code, KEYBOARD, KEYPRESS);
- Sleep(to_hold.after);
- }
- // HoldKey - Overload
- void HoldKey(const key_code& to_hold, const time_ms& before, const time_ms& after)
- {
- Sleep(before);
- INPUT ip;
- ip.type = INPUT_KEYBOARD;
- ip.ki.wScan = 0;
- ip.ki.time = 0;
- ip.ki.dwExtraInfo = 0;
- ip.ki.wVk = to_hold;
- ip.ki.dwFlags = 0;
- SendInput(1, &ip, sizeof(INPUT));
- Sleep(after);
- }
- // ReleaseKey
- void ReleaseKey(const key& to_release)
- {
- Input input(to_release.code, KEYBOARD, KEYRELEASE);
- Sleep(to_release.after);
- }
- // ReleaseKey - Overload
- void ReleaseKey(const key_code& to_release, const time_ms& after)
- {
- INPUT ip;
- ip.type = INPUT_KEYBOARD;
- ip.ki.wScan = 0;
- ip.ki.time = 0;
- ip.ki.dwExtraInfo = 0;
- ip.ki.wVk = to_release;
- ip.ki.dwFlags = KEYEVENTF_KEYUP;
- SendInput(1, &ip, sizeof(INPUT));
- Sleep(after);
- }
- // RightClick
- void RightClick(const time_ms& sleep_after)
- {
- INPUT Input = { 0 };
- Input.type = INPUT_MOUSE;
- Input.mi.dwFlags = MOUSEEVENTF_RIGHTDOWN;
- ::SendInput(1, &Input, sizeof(INPUT));
- ::ZeroMemory(&Input, sizeof(INPUT));
- Input.type = INPUT_MOUSE;
- Input.mi.dwFlags = MOUSEEVENTF_RIGHTUP;
- ::SendInput(1, &Input, sizeof(INPUT));
- Sleep(sleep_after);
- }
- // LeftClick
- void LeftClick(const time_ms& sleep_after)
- {
- INPUT Input = { 0 };
- Input.type = INPUT_MOUSE;
- Input.mi.dwFlags = MOUSEEVENTF_LEFTDOWN;
- ::SendInput(1, &Input, sizeof(INPUT));
- ::ZeroMemory(&Input, sizeof(INPUT));
- Input.type = INPUT_MOUSE;
- Input.mi.dwFlags = MOUSEEVENTF_LEFTUP;
- ::SendInput(1, &Input, sizeof(INPUT));
- Sleep(sleep_after);
- }
- // SetCursor
- void SetCursorPosition(const position& cursor_pos)
- {
- SetCursorPos(cursor_pos.first, cursor_pos.second);
- }
- // GetCursor
- const position GetCursorPosition()
- {
- POINT cursor;
- GetCursorPos(&cursor);
- position cursor_pos{ cursor.x, cursor.y };
- return cursor_pos;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement