2011-04-26 16 views

Respuesta

14
void DoubleClick(int x, int y) 
{ 
    const double XSCALEFACTOR = 65535/(GetSystemMetrics(SM_CXSCREEN) - 1); 
    const double YSCALEFACTOR = 65535/(GetSystemMetrics(SM_CYSCREEN) - 1); 

    POINT cursorPos; 
    GetCursorPos(&cursorPos); 

    double cx = cursorPos.x * XSCALEFACTOR; 
    double cy = cursorPos.y * YSCALEFACTOR; 

    double nx = x * XSCALEFACTOR; 
    double ny = y * YSCALEFACTOR; 

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

    Input.mi.dx = (LONG)nx; 
    Input.mi.dy = (LONG)ny; 

    Input.mi.dwFlags = MOUSEEVENTF_MOVE | MOUSEEVENTF_ABSOLUTE | MOUSEEVENTF_LEFTDOWN | MOUSEEVENTF_LEFTUP; 

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

    Input.mi.dx = (LONG)cx; 
    Input.mi.dy = (LONG)cy; 

    Input.mi.dwFlags = MOUSEEVENTF_MOVE | MOUSEEVENTF_ABSOLUTE; 

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

Puede utilizar GetWindowRect() para obtener la posición de la ventana de su mango y pasar relativa x y y a la función de DoubleClick:

RECT rect; 
GetWindowRect(hwnd, &rect); 

HWND phwnd = GetForegroundWindow(); 

SetForegroundWindow(hwnd); 

DoubleClick(rect.left + x, rect.top + y); 

SetForegroundWindow(phwnd); // To activate previous window 
1

Hay un fragmento de código en this website. Intente utilizar la función LeftClick() dos veces seguidas. Eso hace el truco según this guy.

2

Puede especificar su objetivo (el mejor) o el método, pero si intentas especificar ambos, la mayoría de las veces la respuesta será "eso no funciona así".

SendInput no funciona de esa manera, simula la actividad del mouse en la pantalla, que se entregará a cualquier ventana visible en esa ubicación (o tiene captura de mouse), no la ventana de su elección.

Para entregar un doble clic en una ventana específica, intente PostMessage(hwnd, WM_LBUTTONDBLCLK, 0, MAKEDWORD(x, y)).

4

Esto simulará un doble clic en ciertas coordenadas

SetCursorPos(X,Y); 
    mouse_event(MOUSEEVENTF_LEFTDOWN | MOUSEEVENTF_LEFTUP,0,0,0,0); 
    mouse_event(MOUSEEVENTF_LEFTDOWN | MOUSEEVENTF_LEFTUP,0,0,0,0); 
0

Desde mi 'reputación' no es lo suficientemente alta (aún), me gustaría hacer comentarios sobre la solución # de fardjad: funciona muy bien, pero uno podría agregar siguiente a la rutina "principal":

SetForegroundWindow(hwnd); 
SetCursorPos(rect.left + x, rect.top + y); 
// which shows your current mouseposition... 
// during my testing, I used a _getch() so that I actually could verify it 
Sleep(nWinSleep); 
// delay the mouseclick, as window might not get to foreground quick enough; 
    took me awhile to figure this one out... 
DoubleClick(rect.left + x, rect.top + y); 
Cuestiones relacionadas