Advertisement
Guest User

Untitled

a guest
Jun 26th, 2012
25
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.72 KB | None | 0 0
  1. // TestSendInputMinecraft.cpp : definisce il punto di ingresso dell'applicazione console.
  2. //
  3.  
  4. #include "stdafx.h"
  5.  
  6. #define MOTION_AMOUNT 4
  7.  
  8. struct mouseMovement
  9. {
  10.     int x;
  11.     int y;
  12. };
  13.  
  14. void moveMouse(mouseMovement *movement);
  15. void doTest();
  16.  
  17. int APIENTRY _tWinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPTSTR lpCmdLine, int nCmdShow)
  18. {
  19.     MSG message;
  20.  
  21.     if (IsDebuggerPresent())
  22.     {
  23.         AllocConsole();
  24.     }
  25.  
  26.     RegisterHotKey(NULL, 1, MOD_CONTROL | MOD_NOREPEAT, 0x54); // ctrl+t, test
  27.     RegisterHotKey(NULL, 1, MOD_CONTROL | MOD_NOREPEAT, 0x59); // ctrl+y, esci
  28.  
  29.     memset(&message, 0, sizeof(MSG));
  30.  
  31.     while (GetMessage(&message, NULL, 0, 0) != 0)
  32.     {
  33.         if (message.message == WM_HOTKEY)
  34.         {
  35.             switch (HIWORD(message.lParam))
  36.             {
  37.             case 0x54: // t
  38.                 printf("TEST\n");
  39.                 doTest();
  40.                 break;
  41.             case 0x59: // y
  42.                 return 0;
  43.                 break;
  44.             }
  45.         }
  46.     }
  47.  
  48.     return 1;
  49. }
  50.  
  51. void doTest()
  52. {
  53.     int i, j;
  54.     mouseMovement directions[4];
  55.  
  56.     directions[0].x =  1 * MOTION_AMOUNT; // destra
  57.     directions[0].y =  0 * MOTION_AMOUNT;
  58.  
  59.     directions[1].x =  0 * MOTION_AMOUNT; // basso
  60.     directions[1].y =  1 * MOTION_AMOUNT;
  61.  
  62.     directions[2].x = -1 * MOTION_AMOUNT; // sinistra
  63.     directions[2].y =  0 * MOTION_AMOUNT;
  64.  
  65.     directions[3].x =  0 * MOTION_AMOUNT; // alto
  66.     directions[3].y = -1 * MOTION_AMOUNT;
  67.    
  68.     for (i = 0; i < 4; i++)
  69.     {
  70.         for (j = 0; j < 100; j++)
  71.         {
  72.             moveMouse(&directions[i]);
  73.             Sleep(10);
  74.         }
  75.     }
  76.  
  77.     return;
  78. }
  79.  
  80. void moveMouse(mouseMovement *movement)
  81. {
  82.     INPUT input;
  83.  
  84.     memset(&input, 0, sizeof(INPUT));
  85.  
  86.     input.type = INPUT_MOUSE;
  87.  
  88.     input.mi.dwFlags = MOUSEEVENTF_MOVE;
  89.  
  90.     input.mi.dx = movement->x;
  91.     input.mi.dy = movement->y;
  92.  
  93.     SendInput(1, &input, sizeof(INPUT));
  94.  
  95.     return;
  96. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement