برق، الکترونیک، الکتروتکنیک، مکاترونیک، پزشکی، کشاورزی

برق، الکترونیک، الکتروتکنیک، مکاترونیک، پزشکی، کشاورزی و

برق، الکترونیک، الکتروتکنیک، مکاترونیک، پزشکی، کشاورزی

برق، الکترونیک، الکتروتکنیک، مکاترونیک، پزشکی، کشاورزی و

داده هایی در مورد برق، الکترونیک، الکتروتکنیک، مکاترونیک، پزشکی، کشاورزی و

تبلیغات
آخرین نظرات

کنترل موس

ShahBaz | شنبه, ۳۰ مرداد ۱۳۹۵، ۱۰:۴۴ ق.ظ

C++ move mouse in windows using SetCursorPos

6 down vote favorite

I created a device similar to a wiimote and i want to use it as a mouse in windows (8.1). The device connects over tcp to a c++ win32 program on my windows computer and sends the position where the mouse cursor should move. I am using the SetCursorPos function to set the position, which works great to control most programs. But when I try to control for example the task manager, the cursor doesn't move anymore. When I switch from the task manager back to some other program it works again. I also tried to use the SendInput function with the same results.

This is what my code looks like with SendInput:

INPUT Input = { 0 };
Input.type = INPUT_MOUSE;

Input.mi.dx = (LONG)posX;
Input.mi.dy = (LONG)posY;

// set move cursor directly
Input.mi.dwFlags = MOUSEEVENTF_MOVE | MOUSEEVENTF_ABSOLUTE;

SendInput(1, &Input, sizeof(INPUT));

With SetCursorPos it's just one line:

SetCursorPos(posX, posY);

Can anybody tell me why it doesn't work for some programs? I know it has to be possible to do this, since I tried a smartphone app which controls the cursor and it worked in all programs.

You cannot set the cursor position or input of a window that required higher privileges than your program has..

If you want your program to be able to move the cursor over task manager, you require the same privileges as task manager: Administrator Privileges.

This is how it is done on Windows 8+.

I tried it with the following:

int main()
{
    HWND window = FindWindow("TaskManagerWindow", "Task Manager");
    if (window)
    {
        RECT rect = {0};
        GetWindowRect(window, &rect);

        SetForegroundWindow(window);
        SetActiveWindow(window);
        SetFocus(window);
        Sleep(300);
        SetCursorPos(rect.right - 200, rect.bottom - 200);
    }

    return 0;
}

Cursor only moves over task manager when ran as admin. It is the same for all context menus and windows in Windows 8+. Not just task manager.

https://msdn.microsoft.com/en-us/library/windows/desktop/ms648394(v=vs.85).aspx


http://docs.opencv.org/3.1.0/dc/d3b/classcv_1_1viz_1_1MouseEvent.html#details

اینا برای این هست که مختصات موس به برنامه ای که با اپن سی وی نوشته شده داده بشه. در صورتی که من برعکسش رو میخوام.
یعنی میخوام مختصات از برنامه به موس داده بشه. که توابعی در اپن سی وی برای این کار وجود نداره.
باید در سی ++ به دنبال کتابخونه ای که اینکار رو انجام میده بگردم.


http://randomlinux.com/around-the-web/xdotool-mouse/

این کد رو داخل ترمینال بزنی موس به مختصات 500 و 500 میره
xdotool mousemove 500 500

برای استفاده در برنامه هایی که به زبان سی ++ نوشه می شوند باید کتابخانه های

#include <iostream>
#include <stdio.h>
#include <math.h>
#include <vector>


اینکلود شده باشند.

---------------------------------------


http://forum.ubuntu.ir/index.php/topic,138781.0.html

  • ShahBaz

کنترل موس

نظرات  (۰)

هیچ نظری هنوز ثبت نشده است

ارسال نظر

ارسال نظر آزاد است، اما اگر قبلا در بیان ثبت نام کرده اید می توانید ابتدا وارد شوید.
شما میتوانید از این تگهای html استفاده کنید:
<b> یا <strong>، <em> یا <i>، <u>، <strike> یا <s>، <sup>، <sub>، <blockquote>، <code>، <pre>، <hr>، <br>، <p>، <a href="" title="">، <span style="">، <div align="">
تجدید کد امنیتی