Jump to content

Control mouse on remote


Recommended Posts

Hello AutoIt community!

I am working on a project right now, but I'm kinda stuck.

The script I'm making is about connecting to a remote computer.

This is working already, that's no problem.

My only problem is that I don't know how I could control the mouse of the remote computer.

Like, is it possible to use your own mouse to control the mouse of the remote computer?

Or are there any other solutions? Maybe you have an example script?? :)

Thanks! ;)

- Zeq

Link to comment
Share on other sites

If you mean an AutoIt script running locally controlling the mouse remotely, no.

If you mean running the script on the remote computer, then yes.

Of course, Windows has built in tools for this kind of thing already, like RDP, Remote Assistance, and Admin Terminal Services on servers. And when using those tools I still don't think your local script has any desktop control of the remote session's desktop.

;)

Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law
Link to comment
Share on other sites

What I have right now, is a script on my computer that is the server.

The remote pc has a script that connects to my pc.

With that, I'm already able to send commands to the remote computer to do specific actions.

The only thing I'm focussing on is if I could use my own mouse (mouse of server) to control the remote pc (mouse of client).

Added 2 attachments of the scripts ;)

server.au3

client.au3

Link to comment
Share on other sites

What I have right now, is a script on my computer that is the server.

The remote pc has a script that connects to my pc.

With that, I'm already able to send commands to the remote computer to do specific actions.

The only thing I'm focussing on is if I could use my own mouse (mouse of server) to control the remote pc (mouse of client).

So the server does MouseGetPos(), sends the coordinates to the client, and the client does MouseMove().

Sounds pretty straight forward.

;)

Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law
Link to comment
Share on other sites

It's like PsaltyDS said. It's how any remote control program protocol works.

PC1 : do something => send the infomation to PC2 says that "I'm PC1, I'm doing something"

PC2 : receive message => "ok you did that, then I do this"

Specifically, if you move your mouse on PC1, simply send information the mouse coordinate of PC1 to PC2 and PC2 will simulate the same thing with the mouse.

Link to comment
Share on other sites

Then can you answer this question for me?

At server side, I save the MouseGetPos(0) data (X) into variable $x.

Same with MouseGetPos(1) (Y), I save that into variable $y.

How could I send $x and $y to the client?

If I would do TCPsend, the data would be saved into $tFunc.

So I would do MouseMove($tFunc , $tFunc, 1).

I think that that wouldn't give me the thing I want.

So, maybe you guys know? Or have an example script?

Link to comment
Share on other sites

strore $x and $y as a string of information

$data = $x & $y & $buttonclick & .... etc.

Then use TCPSend to send it. You need TCP/IP knowledge and if you wish to connect to a pc not at your home ,refer to this thread http://www.autoitscript.com/forum/index.php?showtopic=120553

The best way to start is to be familiar with the TCP functions first. Have 2 pc at home then test

Edited by trung0407
Link to comment
Share on other sites

  • 4 weeks later...

Just stumbled across this when i was searching for help with the exact same project.

im also working on a server/client remote control as such that will control my media server - RD is a pain when it logs off :(

Currently stuck on getting an image into the gui so i can actually see where im clicking when the other comp isnt next to me :graduated:

well anyways this is what i have. hope it helps you!

Send.au3

#include <Misc.au3>
#include <WindowsConstants.au3>
#include <GUIConstantsEx.au3>
#include <GDIPlus.au3>

TCPStartup()
$ip = InputBox("Address", "ip", "192.168.0.2", " M")
$_sock = TCPConnect($ip, 33891)
If @error Then Exit MsgBox(16, "Wsa:" & @error, "Unable to connect to the host!")
$click = ""
Do
    $recv = TCPRecv($_sock, 1000)
    If @error Then Exit MsgBox(16, "WSA:" & @error, "Lost connection!")
    Sleep(1)
Until $recv <> ""
TCPSend($_sock, "OK")
$stat = StringSplit($recv, "|")
$GUI = GUICreate("Remotey", $stat[1], $stat[2], 0, 0,$WS_SYSMENU, $WS_EX_TOPMOST)
$gui_graphic = GUICtrlCreatePic($GUI, 0, 0, $stat[1], $stat[2] + 20)
GUISetState()


While 1
    $pos = GUIGetCursorInfo()
    If _IsPressed(01) Then $click = "Lclick"
    If _IsPressed(02) Then $click = "Rclick"
    TCPSend($_sock, $pos[0] & "|" & $pos[1] & "|" & $click)
    $click = ""
    ToolTip($pos[0] & "|" & $pos[1] & "|" & $click, 0, 0)
    If GUIGetMsg() = $GUI_EVENT_CLOSE Then Exit
    Sleep(1000) 
WEnd

Recive.au3

#Region ;**** Directives created by AutoIt3Wrapper_GUI ****
#AutoIt3Wrapper_UseUpx=n
#EndRegion ;**** Directives created by AutoIt3Wrapper_GUI ****
#include <GUIConstantsEx.au3>
#include <ScreenCapture.au3>

Opt('MustDeclareVars', 1)

; Set Some reusable info
; Set your Public IP address (@IPAddress1) here.
;   Local $szServerPC = @ComputerName
;   Local $szIPADDRESS = TCPNameToIP($szServerPC)
Local $szIPADDRESS = @IPAddress1
Local $nPORT = 33891
Local $MainSocket, $GOOEY, $edit, $ConnectedSocket, $szIP_Accepted
Local $msg, $recv, $recv2
Local $pos


; Start The TCP Services
;==============================================
TCPStartup()

; Create a Listening "SOCKET".
;   Using your IP Address and Port 33891.
;==============================================
$MainSocket = TCPListen($szIPADDRESS, $nPORT)

; If the Socket creation fails, exit.
If $MainSocket = -1 Then Exit


; Create a GUI for messages
;==============================================
$GOOEY = GUICreate("My Server (IP: " & $szIPADDRESS & ")", 300, 200)
$edit = GUICtrlCreateEdit("", 10, 10, 280, 180)
GUISetState()


; Initialize a variable to represent a connection
;==============================================
$ConnectedSocket = -1


;Wait for and Accept a connection
;==============================================
Do
    $ConnectedSocket = TCPAccept($MainSocket)
Until $ConnectedSocket <> -1
; Get IP of client connecting
$szIP_Accepted = SocketToIP($ConnectedSocket)

Do
    TCPSend($ConnectedSocket, @DesktopWidth & "|" & @DesktopHeight)
    $recv2 = TCPRecv($ConnectedSocket, 1000)
    If @error Then Exit MsgBox(16, "WSA:" & @error, "Lost connection!")
    Sleep(1)
Until $recv2 <> ""

; GUI Message Loop
;==============================================
While 1
    $msg = GUIGetMsg()

    ; GUI Closed
    ;--------------------
    If $msg = $GUI_EVENT_CLOSE Then ExitLoop

    ; Try to receive (up to) 2048 bytes
    ;----------------------------------------------------------------
    $recv = TCPRecv($ConnectedSocket, 2048)

    ; If the receive failed with @error then the socket has disconnected
    ;----------------------------------------------------------------
    If @error Then ExitLoop

    ; Update the edit control with what we have received
    ;----------------------------------------------------------------
    If $recv <> "" Then
        GUICtrlSetData($edit, $szIP_Accepted & " > " & $recv & @CRLF & GUICtrlRead($edit))
        $pos = StringSplit($recv, "|")
        MouseMove($pos[1], $pos[2])
        If $pos[3] = "Lclick" Then MouseClick("left")
        If $pos[3] = "Rclick" Then MouseClick("right")
    EndIf
WEnd


If $ConnectedSocket <> -1 Then TCPCloseSocket($ConnectedSocket)

TCPShutdown()


; Function to return IP Address from a connected socket.
;----------------------------------------------------------------------
Func SocketToIP($SHOCKET)
    Local $sockaddr, $aRet
    
    $sockaddr = DllStructCreate("short;ushort;uint;char[8]")

    $aRet = DllCall("Ws2_32.dll", "int", "getpeername", "int", $SHOCKET, _
            "ptr", DllStructGetPtr($sockaddr), "int*", DllStructGetSize($sockaddr))
    If Not @error And $aRet[0] = 0 Then
        $aRet = DllCall("Ws2_32.dll", "str", "inet_ntoa", "int", DllStructGetData($sockaddr, 3))
        If Not @error Then $aRet = $aRet[0]
    Else
        $aRet = 0
    EndIf

    $sockaddr = 0

    Return $aRet
EndFunc   ;==>SocketToIP
http://twentylinesofcode.blogspot.comLittle apps n crap. can be fun
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...