Skip to content

Instantly share code, notes, and snippets.

@tmwatchanan
Created January 7, 2021 03:09
Show Gist options
  • Save tmwatchanan/f53bb5dc9654982080dcbe6efc3406ba to your computer and use it in GitHub Desktop.
Save tmwatchanan/f53bb5dc9654982080dcbe6efc3406ba to your computer and use it in GitHub Desktop.
#include <windows.h>
#include <iostream>
#include <unistd.h>
using namespace std;
int main()
{
POINT point;
POINT* pts = new POINT[2];
int time = 1; // seconds
GetCursorPos(&point);
pts[0] = point;
cout << pts[0].x << " " << pts[0].y << endl;
sleep(time);
GetCursorPos(&point);
pts[1] = point;
cout << pts[1].x << " " << pts[1].y << endl;
double speed_x = (pts[1].x - pts[0].x) / static_cast<double>(time);
double speed_y = (pts[1].y - pts[0].y) / static_cast<double>(time);
cout << "speed x = " << speed_x << " pixels/s" << endl;
cout << "speed y = " << speed_y << " pixels/s" << endl;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment