Autor Tema: Mover Mouse de forma remota?? [SOLUCIONADO]  (Leído 4012 veces)

0 Usuarios y 1 Visitante están viendo este tema.

Jhonjhon_123

  • Bytes
  • *
  • Mensajes: 24
  • Reputación: +0/-0
    • Ver Perfil
Mover Mouse de forma remota?? [SOLUCIONADO]
« en: Diciembre 28, 2009, 03:59:49 pm »
Hola!

tengo el sig codigo para obtener las coordenadas en relacion a mi pantalla con un picturebox:

Código: [Seleccionar]
Private Sub Pic_IMG_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)

Dim PosRealX As Single
Dim PosRealY As Single

Difer = Screen.Width / Pic_IMG.Width
PosRealX = X * Difer / Screen.TwipsPerPixelX
 
Difer = Screen.Height / Pic_IMG.Height
PosRealY = Y * Difer / Screen.TwipsPerPixelY

//Lo envia por WinSock
Enviar "mouse_img[$$]" & _
        PosRealX & "[$$]" & _
        PosRealY & "[$$]" & _
        Screen.Width & "[$$]" & _
        Screen.Height & "[$$]" & _
        Button, VIndex

End Sub

Donde "PosRealX y PosRealY" son las coordenadas reales de mi pc

y en el pc Remoto el sig codigo:

Código: [Seleccionar]
Public Function MoverMouse(X As Single, Y As Single, PCW As Integer, PCH As Integer, Button As Integer)

Dim PosRealX As Single
Dim PosRealY As Single

PosRealX = (X * Screen.Width) / PCW
PosRealY = (Y * Screen.Height) / PCH

Call SetCursorPos(PosRealX, PosRealY)

If Button = 1 Then
    Call mouse_event(MOUSEEVENTF_LEFTDOWN, 0&, 0&, 0&, 0&)
    Call mouse_event(MOUSEEVENTF_LEFTUP, 0&, 0&, 0&, 0&)
ElseIf Button = 2 Then
    Call mouse_event(MOUSEEVENTF_RIGHTDOWN, 0&, 0&, 0&, 0&)
    Call mouse_event(MOUSEEVENTF_RIGHTUP, 0&, 0&, 0&, 0&)
End If

End Function

Donde "PCW" es "Screen.Width" de mi pc y "PCH" es "Screen.Height" de mi pc

El problema es que no me da igual la medida al combertirla en el pc remoto, el mouse se mueve un poco mas alla o aca de la pocicion deseada

Por que me pasa esto, estoy seguro de que algo falla en esas formulas, pero no se que es ¿Que es?

Gracias por su atencion!
« última modificación: Enero 17, 2010, 09:49:35 pm por Jhonjhon_123 »

LeandroA

  • Administrador
  • Petabyte
  • *****
  • Mensajes: 1128
  • Reputación: +151/-8
    • Ver Perfil
Re:Mover Mouse de forma remota??
« Respuesta #1 en: Diciembre 28, 2009, 07:06:22 pm »
hola son simples regla de tres te pongo un ejemplo utilizando dos pictureBox que simulan las pantallas

Código: [Seleccionar]
Option Explicit

Private Sub Picture1_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
    Dim PercentX As Long
    Dim PercentY As Long

    PercentX = (X * 100) / Picture1.ScaleWidth
    PercentY = (Y * 100) / Picture1.ScaleHeight
    Picture2.Cls
    Picture2.DrawWidth = 5
    Picture2.PSet ((Picture2.ScaleWidth * PercentX) / 100, (Picture2.ScaleHeight * PercentY) / 100)
End Sub


entonces analizemos solo la X
primero devemos obtener que valor en porcentage ocupa la x del mouse en la pantalla local

pantallaLocalWithd _____________ 100%
x  ___________________________  (x * 100) / pantallaLocalWithd  <----- PercentX

Luego devemos aplicar la posicion x en la pantalla remota segun el porcentaje

x = (pantallaRemotaWithd  * PercentX) / 100

Es lo unico que entiendo en matematicas :)

Saludos.


Jhonjhon_123

  • Bytes
  • *
  • Mensajes: 24
  • Reputación: +0/-0
    • Ver Perfil
Re:Mover Mouse de forma remota??
« Respuesta #2 en: Diciembre 28, 2009, 09:30:53 pm »
Lo he puesto hasi:

PC local:

Código: [Seleccionar]
Private Sub Pic_IMG_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)

Dim PosRealX As Single
Dim PosRealY As Single

'Difer = Screen.Width / Pic_IMG.Width
'PosRealX = X * Difer / Screen.TwipsPerPixelX
 
'Difer = Screen.Height / Pic_IMG.Height
'PosRealY = Y * Difer / Screen.TwipsPerPixelY


PosRealX = (X * 100) / Pic_IMG.ScaleWidth
PosRealY = (Y * 100) / Pic_IMG.ScaleHeight

Enviar "mouse_img" & SEP & _
        PosRealX & SEP & _
        PosRealY & SEP & _
        Screen.Width & SEP & _
        Screen.Height & SEP & _
        Button, VIndex

End Sub

PC remoto:

Código: [Seleccionar]
Public Function MoverMouse(X As Single, Y As Single, PCW As Integer, PCH As Integer, Button As Integer)

Dim PosRealX As Single
Dim PosRealY As Single

'PosRealX = (X * Screen.Width) / PCW
'PosRealY = (Y * Screen.Height) / PCH

PosRealX = (Screen.Width * X) / 100
PosRealY = (Screen.Width * Y) / 100

Call SetCursorPos(PosRealX, PosRealY)

If Button = 1 Then
    Call mouse_event(MOUSEEVENTF_LEFTDOWN, 0&, 0&, 0&, 0&)
    Call mouse_event(MOUSEEVENTF_LEFTUP, 0&, 0&, 0&, 0&)
ElseIf Button = 2 Then
    Call mouse_event(MOUSEEVENTF_RIGHTDOWN, 0&, 0&, 0&, 0&)
    Call mouse_event(MOUSEEVENTF_RIGHTUP, 0&, 0&, 0&, 0&)
End If

End Function

pero no me da, ni siquiera se acerca a la coordenada, por que??

LeandroA

  • Administrador
  • Petabyte
  • *****
  • Mensajes: 1128
  • Reputación: +151/-8
    • Ver Perfil
Re:Mover Mouse de forma remota??
« Respuesta #3 en: Diciembre 28, 2009, 10:18:43 pm »
no se si estas trabajando en vbpixels, pero suponiendo que si lo estas haciendo

PosRealX = ((Screen.Width / Screen.TwipsPerPixelX) * X) / 100


y si no lo estas haciendo

Call SetCursorPos(PosRealX  / Screen.TwipsPerPixelX, PosRealY  / Screen.TwipsPerPixelY)

las apis (SetCursorPos) trabajan en pixels y si vos estas trabajando en Twips seguramente no te va a andar
tambien tene en cuenta que Screen.Width esta en Twips

si corregis eso tendria que andar.

Saludos.

Jhonjhon_123

  • Bytes
  • *
  • Mensajes: 24
  • Reputación: +0/-0
    • Ver Perfil
Re:Mover Mouse de forma remota??
« Respuesta #4 en: Diciembre 30, 2009, 09:06:07 pm »
Bueno, parese que todo era cuestion de ller un poco, ya lo solucione:

Cliente:

Código: [Seleccionar]

Dim PantallaLocalX As Single, PantallaLocalY As Single
Dim XReal As Single, YReal As Single

PantallaLocalX = Screen.Width / Screen.TwipsPerPixelX
XReal = (X * PantallaLocalX) / Pic_IMG.ScaleWidth

PantallaLocalY = Screen.Height / Screen.TwipsPerPixelY
YReal = (Y * PantallaLocalY) / Pic_IMG.ScaleHeight

Server:

Código: [Seleccionar]
Dim PantallaRemotaX As Single, PantallaRemotaY As Single
Dim XReal2 As Single, YReal2 As Single

PantallaRemotaX = Screen.Width / Screen.TwipsPerPixelX
XReal2 = (X * PantallaRemotaX) / PCW

PantallaRemotaY = Screen.Height / Screen.TwipsPerPixelY
YReal2 = (Y * PantallaRemotaY) / PCH

Gracias Por la paciencia!