Move mouse with c++ menu

User Tag List

Results 1 to 2 of 2
  1. #1
    sabatos's Avatar Private
    Reputation
    1
    Join Date
    Jun 2012
    Posts
    5
    Thanks G/R
    0/0
    Trade Feedback
    0 (0%)
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Move mouse with c++

    I started playing with c++ and managed to simulate mouse clicks. I am just curious that I dont see the mouse cursor move at all.
    I am using Visual C++ 2010 Express in a Windows 7 inside Parallels and I created a console application.

    Here is my code in case you want to check it and give me some advice:
    Code:
    #include <Windows.h>
    #include <Tlhelp32.h>
    #include <stdio.h>
    #include <string>
    #include <iostream>
    #include <fstream>
    #include <sstream>
    #include <time.h>
    
    void mouseLeftClick(const int x, const int y);
    
    // window
    HWND hWindow;
    
    int main()
    {
        // find window
        hWindow = FindWindow(NULL, "Calculadora");
    
        if (NULL == hWindow) {
            OutputDebugStringA("Couldn't find application.");
        }else{
    
            if (!SetForegroundWindow(hWindow)) {
                OutputDebugStringA("Couldn't set application to foreground.");
            }else{
                // click on 1
                mouseLeftClick(20 265));
                Sleep(500);
                // click on 2
                mouseLeftClick(60, 265);
                Sleep(500);
            }
        }
        return 0;
    }
    
    void mouseLeftClick(const int x, const int y)
    { 
        // get the window position
        RECT rect;
        GetWindowRect(hWindow, &rect);
    
        // calculate scale factor
        const double XSCALEFACTOR = 65535 / (GetSystemMetrics(SM_CXSCREEN) - 1);
        const double YSCALEFACTOR = 65535 / (GetSystemMetrics(SM_CYSCREEN) - 1);
    
        // get current position
        POINT cursorPos;
        GetCursorPos(&cursorPos);
        double cx = cursorPos.x * XSCALEFACTOR;
        double cy = cursorPos.y * YSCALEFACTOR;
    
        // calculate target position relative to application
        double nx = (x + rect.left) * XSCALEFACTOR;
        double ny = (y + rect.top) * YSCALEFACTOR;
    
        INPUT Input={0};
        Input.type = INPUT_MOUSE;
    
        Input.mi.dx = (LONG)nx;
        Input.mi.dy = (LONG)ny;
    
        // set move cursor directly and left click
        Input.mi.dwFlags = MOUSEEVENTF_MOVE | MOUSEEVENTF_ABSOLUTE | MOUSEEVENTF_LEFTDOWN | MOUSEEVENTF_LEFTUP;
    
        SendInput(1,&Input,sizeof(INPUT));
    }
    Thanks in advance!

    Move mouse with c++
  2. #2
    sabatos's Avatar Private
    Reputation
    1
    Join Date
    Jun 2012
    Posts
    5
    Thanks G/R
    0/0
    Trade Feedback
    0 (0%)
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I found the problem. It turns out Parallels has a feature called Smart Mouse that allows you move freely between OSX and Windows. Once I deactivated it, mouse moves as expected.

Similar Threads

  1. [Hack] How does Overwatch Mouse Sensitivity correlate to Moving the mouse with C++?
    By seldane in forum Overwatch Exploits|Hacks
    Replies: 4
    Last Post: 07-09-2016, 12:17 PM
  2. Replies: 3
    Last Post: 10-14-2012, 05:28 PM
  3. Giant Rabbits, Mouses with Shotguns
    By Classicclean in forum World of Warcraft Exploration
    Replies: 6
    Last Post: 03-04-2011, 05:48 PM
  4. Java Applet Move object with mouse
    By Zantas in forum Programming
    Replies: 1
    Last Post: 06-02-2010, 12:53 PM
  5. [Question] Moving m2 with Noggit
    By jasperjag in forum WoW ME Questions and Requests
    Replies: 3
    Last Post: 12-21-2007, 03:41 PM
All times are GMT -5. The time now is 02:48 PM. Powered by vBulletin® Version 4.2.3
Copyright © 2024 vBulletin Solutions, Inc. All rights reserved. User Alert System provided by Advanced User Tagging (Pro) - vBulletin Mods & Addons Copyright © 2024 DragonByte Technologies Ltd.
Digital Point modules: Sphinx-based search