I have an application which is supposed to move the mouse based on input like that from a keyboard. the code listens for the direction keys to see if they are pressed. the code works but only in 2 direction it can only move to the right and down. is there any way to move it up and left to.
Here is the code:
#include <windows.h>
#include <iostream>
#include <cstdlib>
void MoveMouse(int x, int y);
using namespace std;
int main(){
bool boo = true;
int x = 0;
int y = 0;
while(boo){
if(GetKeyState(VK_LEFT)<0){
x--;
if(x < 0){
x = 0;
}
MoveMouse(x,NULL);
}
if(GetKeyState(VK_RIGHT)<0){
x++;
if(x < 0){
x = 0;
}
MoveMouse(x,NULL);
}
if(GetKeyState(VK_UP)<0){
y--;
if(y < 0){
y = 0;
}
MoveMouse(NULL,y);
}
if(GetKeyState(VK_DOWN)<0){
y++;
if(y < 0){
y = 0;
}
MoveMouse(NULL,y);
}
if(GetKeyState(VK_SPACE)<0){
boo = false;
}
Sleep(30);
system("cls");
cout << x << endl;
cout << y << endl;
}
system("cls");
}
void MoveMouse(int x, int y){
int buffer;
for(buffer = 0; x >= buffer && y >= buffer; buffer++){
mouse_event(0x0001,x,y,NULL,NULL);
Sleep(1);
}
}
also if anyone can help is there any way to control the mouse and clicks with a serial input. if you need more info just ask and is there a way for me to be able to click outside of the console window but still control the mouse with the program