can you please tell how you would invert the mouse control so that up is down, left is right etc.

can you please tell how you would invert the mouse control so that up is down, left is right etc.

You don't need any hook (!)
Simply use Win32 System apis (2 lines of code to swap mouse buttons...)

commented: no -4
Member Avatar for iamthwee

It's got nothing to do with mouse buttons, it's mouse movement.

You don't need any hook (!)
Simply use Win32 System apis (2 lines of code to swap mouse buttons...)

hey can u pls explain me how exactly to invert it??...what lines to change and all??....thanks in advance

Rotate the mouse on your desk through 180 degrees.

Rotate the mouse on your desk through 180 degrees.

LOL :)

Working program

#include <windows.h>

void getcoords(int &x, int &y) {
POINT cursorPos;
        GetCursorPos(&cursorPos);
        x = cursorPos.x;
        y = cursorPos.y;
        }

int main() {
    int x,y;
    int x2,y2;
    int dx,dy;

    while(true) {

    getcoords(x,y);
    Sleep(30);
    getcoords(x2,y2);

    dx = x2 - x;
    dy = y2 - y;
    SetCursorPos(x-dx,y-dy);
    }

return 0;
}

To make the program work more smoothly decrease the Sleep() time

Wait, It doesnt work yet. I have to edit it a little bit more

Now it works for top 2 corners but not for the buttom 2 corners, I am not sure why

#include <windows.h>
#include <iostream>

void getcoords(int &x, int &y);

bool equals(int n1, int n2);

using namespace std;

int main() {
    int x,y; //first x and y
    int x2,y2; //second x and y
    int dx,dy; //difference

SetCursorPos(9999,9999);
int mx,my; //max x and max y on the particular screen
getcoords(mx,my);

SetCursorPos(-50,-50);
int minx,miny;
getcoords(minx,miny);

 //   int g;
// std::cin >> g;

    while(true) {
getcoords(x,y);
    Sleep(3);
getcoords(x2,y2);



if(equals(x,mx)) {
x = x-2;
}

if(equals(x2,mx)) {
x2 = x2-2;
}

if(equals(y2,mx)) {
y2 = y2-2;
}

if(equals(y,mx)) {
y = y-2;
}









if(equals(x,minx)) {
x = x+2;
}

if(equals(x2,minx)) {
x2 = x2+2;
}

if(equals(y2,minx)) {
y2 = y2+2;
}

if(equals(y,minx)) {
y = y+2;
}


SetCursorPos(x2,y2);

    dx = x2 - x;
    dy = y2 - y;
    SetCursorPos(x-dx,y-dy);
    }


return 0;
}


bool equals(int n1, int n2) {
if(abs(n1-n2) < 3) {
return true;
}
else {
return false;
}

   }

void getcoords(int &x, int &y) {
POINT cursorPos;
        GetCursorPos(&cursorPos);
        x = cursorPos.x;
        y = cursorPos.y;
        }

LOL I made a stupid mistake last time. THis works perfectly. Increasing Sleep(); makes the computer use less resources but it makes the program less smoother. So if you need really smooth mouse decrease sleep and if you dont wont to take much computer resources increase sleep

#include <windows.h>
#include <iostream>

void getcoords(int &x, int &y);

bool equals(int n1, int n2);

using namespace std;

int main() {
    int x,y; //first x and y
    int x2,y2; //second x and y
    int dx,dy; //difference

SetCursorPos(-50,-50);
int minx,miny;
getcoords(minx,miny);

SetCursorPos(9999,9999);
int mx,my; //max x and max y on the particular screen
getcoords(mx,my);



 //   int g;
// std::cin >> g;

    while(true) {
getcoords(x,y);
    Sleep(3);
getcoords(x2,y2);



if(equals(x,mx)) {
x = x-2;
}

if(equals(x2,mx)) {
x2 = x2-2;
}

if(equals(y2,my)) {
y2 = y2-2;
}

if(equals(y,my)) {
y = y-2;
}









if(equals(x,minx)) {
x = x+2;
}

if(equals(x2,minx)) {
x2 = x2+2;
}

if(equals(y2,miny)) {
y2 = y2+2;
}

if(equals(y,miny)) {
y = y+2;
}


SetCursorPos(x2,y2);

    dx = x2 - x;
    dy = y2 - y;
    SetCursorPos(x-dx,y-dy);
    }


return 0;
}


bool equals(int n1, int n2) {
if(abs(n1-n2) < 3) {
return true;
}
else {
return false;
}

   }

void getcoords(int &x, int &y) {
POINT cursorPos;
        GetCursorPos(&cursorPos);
        x = cursorPos.x;
        y = cursorPos.y;
        }

LOL I made a stupid mistake last time. THis works perfectly. Increasing Sleep(); makes the computer use less resources but it makes the program less smoother. So if you need really smooth mouse decrease sleep and if you dont wont to take much computer resources increase sleep

#include <windows.h>
#include <iostream>

void getcoords(int &x, int &y);

bool equals(int n1, int n2);

using namespace std;

int main() {
    int x,y; //first x and y
    int x2,y2; //second x and y
    int dx,dy; //difference

SetCursorPos(-50,-50);
int minx,miny;
getcoords(minx,miny);

SetCursorPos(9999,9999);
int mx,my; //max x and max y on the particular screen
getcoords(mx,my);



 //   int g;
// std::cin >> g;

    while(true) {
getcoords(x,y);
    Sleep(3);
getcoords(x2,y2);



if(equals(x,mx)) {
x = x-2;
}

if(equals(x2,mx)) {
x2 = x2-2;
}

if(equals(y2,my)) {
y2 = y2-2;
}

if(equals(y,my)) {
y = y-2;
}









if(equals(x,minx)) {
x = x+2;
}

if(equals(x2,minx)) {
x2 = x2+2;
}

if(equals(y2,miny)) {
y2 = y2+2;
}

if(equals(y,miny)) {
y = y+2;
}


SetCursorPos(x2,y2);

    dx = x2 - x;
    dy = y2 - y;
    SetCursorPos(x-dx,y-dy);
    }


return 0;
}


bool equals(int n1, int n2) {
if(abs(n1-n2) < 3) {
return true;
}
else {
return false;
}

   }

void getcoords(int &x, int &y) {
POINT cursorPos;
        GetCursorPos(&cursorPos);
        x = cursorPos.x;
        y = cursorPos.y;
        }

hey thnx a lot...dis inverts both x,y axis...cn u gimme code for y-axis alone..thnx a lot again...n does this work inside a game also???

I don't know, what kind of game? DirectX, OpenGL or other stuff?

I dont think it will work in games :( For that there is probably DirectX3D or DirectX Input functions. I am studying game programming myself right now

To inverse 1 axis you just have to change minus sign to plus

#include <windows.h>
#include <iostream>

void getcoords(int &x, int &y);

bool equals(int n1, int n2);

using namespace std;

int main() {
    int x,y; //first x and y
    int x2,y2; //second x and y
    int dx,dy; //difference

SetCursorPos(-50,-50);
int minx,miny;
getcoords(minx,miny);

SetCursorPos(9999,9999);
int mx,my; //max x and max y on the particular screen
getcoords(mx,my);



 //   int g;
// std::cin >> g;

    while(true) {
getcoords(x,y);
    Sleep(3);
getcoords(x2,y2);



if(equals(x,mx)) {
x = x-2;
}

if(equals(x2,mx)) {
x2 = x2-2;
}

if(equals(y2,my)) {
y2 = y2-2;
}

if(equals(y,my)) {
y = y-2;
}









if(equals(x,minx)) {
x = x+2;
}

if(equals(x2,minx)) {
x2 = x2+2;
}

if(equals(y2,miny)) {
y2 = y2+2;
}

if(equals(y,miny)) {
y = y+2;
}


SetCursorPos(x2,y2);

    dx = x2 - x;
    dy = y2 - y;
    SetCursorPos(x-dx,y-dy); ///CHANGE THIS from minus to plus to inverse
    } //different axises


return 0;
}


bool equals(int n1, int n2) {
if(abs(n1-n2) < 3) {
return true;
}
else {
return false;
}

   }

void getcoords(int &x, int &y) {
POINT cursorPos;
        GetCursorPos(&cursorPos);
        x = cursorPos.x;
        y = cursorPos.y;
        }

So you can change from
SetCursorPos(x-dx,y-dy)
to SetCursorPos(x+dx,y-dy) or
SetCursorPos(x-dx,y+dy)
If you keep both of them + then the mouse will act normal

I know this was a while ago but this program works great, the only problem is when I go to another screen on a multiple monitor setup it sometimes seems to bug out...anyone know what the issues or a fix might be?

This program solves so many problems that sakasa and the one other program that does this has issues with.

Sakasa will bug out it seems with windows 10, this one doesnt seem to have that problem yet except with multiple monitors.

Also I dont have a lot of programming experience, I'm just a copy paster so this was perfect for that but I would love to flesh this code out. Any idea or help pointing me to somewhere so I could turn this into a program that runs as a little icon you know down in your program bar like sakasa instead of an open window? I have no idea where to start with something like that.

The program also seems to make the mouse skip around a bit especially in one spot...is that the setcursorpos function or something..it seems repeatable and not completely random...maybe it jumps to the bottom of the screen for a bit...again maybe this is because of the multiple monitors I'm running....not sure what the issues could be where its bugging out...at least it doesnt completely crash like sakasa.

Yeah so like I can move the mouse up and down between the bottom half of the screen like up and down 10 or so time fairly quickly and all of a sudden the mouse will jump to the top half of the screen....and then same if I repeat it just moving the mouse on the top half up and down it'll all of a sudden jump back down to the bottom half....weird??

Sorry if I don't offer fixes for this but I did something akin to the above long ago on a completely different system. So just some thoughts.

  1. As to the skipping around I'd go over the app and watch out for variables that are a bit too small. That is, are any just 16 bit or such? Could this be an overflow or such issue?
  2. About the screens issue. That would take a bit of work as we research API calls to see which screen the mouse is on and customize the routine for screens 0 to how many? I don't see any code above to detect the screen the mouse is on but it would be required.

Yeah I have 3 different screens all different resolutions.....I tried playing around with the min max values a bit but it just succeeded in breaking it more, it never improved it. The cursor gets stuck at the top or bottom of the screen a lot, especially if I move it to other monitors.

It actually does work so well if it wasnt for the skipping it'd be perfect..it doesnt seem to have the issues that sakasa has where if the focus of programs changes in windows 10 the program bugs out sometimes...and amazing to be actually able to have code I could modify..I just wish I could understand all the functions and what's happening and figure out what the problems are.

I tried contacting the programmer of sakasa but he wrote that program in 2006, and his email seems to no longer be valid.

It appears the 8+ YO code is in need of a rewrite for W8 and on. The same complaint was made about W8.

I see some of the work appears to be at this link.

I found some other discussions about this with this search.

I'm not coder can you tell me how to run this script or point me to a tutorial on how to do it.

commented: Just tried this out. I turned the mouse upside down. Instantly inverted the mouse control with no code! +15
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.