Advertisement
Guest User

Untitled

a guest
Oct 1st, 2016
128
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.53 KB | None | 0 0
  1. #include <Windows.h>
  2. #include <iostream>
  3. #include <thread>
  4. #include <chrono>
  5. #include <string>
  6. #include <fstream>
  7.  
  8. #define callReturn CallNextHookEx((HHOOK)NULL, nCode, wParam, lParam);
  9.  
  10. using namespace std;
  11. KEYBDINPUT kinput[2];
  12. int keyBind[2];
  13. bool key_down[2];
  14.  
  15.  
  16. LRESULT CALLBACK keyboardHookProc(int nCode, WPARAM wParam, LPARAM lParam) {
  17.  
  18.     KBDLLHOOKSTRUCT* kb = (KBDLLHOOKSTRUCT*)lParam;
  19.     int key;
  20.     if (kb->vkCode != keyBind[0] && kb->vkCode != keyBind[1]) return callReturn;   
  21.     if (wParam != WM_KEYDOWN && wParam != WM_KEYUP) return callReturn;
  22.     if (kb->vkCode == keyBind[0])
  23.         key = 0;
  24.     else key = 1;
  25.    
  26.     if (wParam == WM_KEYUP) {
  27.         key_down[key] = false;
  28.         return callReturn;
  29.     }
  30.  
  31.     if (!key_down[key]) {
  32.         kinput[key].dwFlags = 0;
  33.         INPUT inputs[1];
  34.         inputs[0].type = INPUT_KEYBOARD;
  35.         inputs[0].ki = kinput[key];
  36.         int res = SendInput(1, inputs, sizeof(INPUT));
  37.  
  38.         this_thread::sleep_for(chrono::milliseconds(10));
  39.         kinput[key].dwFlags = 2;
  40.         inputs[0].ki = kinput[key];
  41.         res = SendInput(1, inputs, sizeof(INPUT));
  42.         key_down[key] = true;
  43.     }
  44.  
  45.     return callReturn;
  46. }
  47.  
  48. int main(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nShowCmd)
  49. {  
  50.     printf("#########################################################\n");
  51.     printf("#\t\t\t\t\t\t\t#\n");
  52.     printf("#\t\t   osu!mania scratch fix\t\t#\n");
  53.     printf("#\t\t\t\t\t\t\t#\n");
  54.     printf("#\t\t\tHow to use:\t\t\t#\n");
  55.     printf("#\t\t\t\t\t\t\t#\n");
  56.     printf("#\t  Set your two scratch binds in the cfg\t\t#\n");
  57.     printf("#\t  file (windows virtual key codes) and\t\t#\n");
  58.     printf("#\t  bind the scratches in-game to 1 and 2.\t#\n");
  59.     printf("#\t\t\t\t\t\t\t#\n");
  60.     printf("#\t\t\t\t\t\t\t#\n");
  61.     printf("#\t  This app needs to be run as admin or\t\t#\n");
  62.     printf("#\t  osu! will freak out for some reason.\t\t#\n");
  63.     printf("#\t\t\t\t\t\t\t#\n");
  64.     printf("#\t\t\t\t\t\t\t#\n");
  65.     printf("#########################################################\n");
  66.  
  67.     // Init
  68.     ifstream config("scratcher.cfg");
  69.     if (!config.is_open())
  70.         return 0;
  71.     while(!config.eof())
  72.     {
  73.         string line;
  74.         getline(config, line);
  75.         config >> keyBind[0] >> keyBind[1];
  76.     }
  77.     config.close();
  78.  
  79.     kinput[0].wVk = 0x31;
  80.     kinput[0].wScan = 0;
  81.     kinput[0].time = 0;
  82.     kinput[1].wVk = 0x32;
  83.     kinput[1].wScan = 0;
  84.     kinput[1].time = 0;
  85.  
  86.     // Hook
  87.     HHOOK hook = SetWindowsHookEx(WH_KEYBOARD_LL, (HOOKPROC)keyboardHookProc, NULL, 0);
  88.  
  89.     // Handle messages
  90.     MSG msg;
  91.    
  92.     while (GetMessage(&msg, NULL, 0, 0) > 0) {
  93.         TranslateMessage(&msg);
  94.         DispatchMessage(&msg);
  95.     }
  96.  
  97.     return 0;
  98. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement