Server
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 |
##Server while(1) { $port=2040 $IPEndPoint=New-Object System.Net.IPEndPoint([IPAddress]::Any,$port) $UdpClient=New-Object System.Net.Sockets.UdpClient $port #Receive position x,y $positions=[Text.Encoding]::ASCII.GetString($UdpClient.Receive([ref]$IPEndPoint)) $positions #Set cursor's position $x=[Int]$positions.Split(',')[0] $y=[Int]$positions.Split(',')[1]+100 [System.Windows.Forms.Cursor]::Position=New-Object System.Drawing.Point($x,$y) $UdpClient.close() } |
Client
1 2 3 4 5 6 7 8 9 10 11 12 13 |
##Client $port=2040 $IPEndPoint=new-object System.Net.IPEndPoint([IPAddress]::Loopback,$port) #Position x,y $x=([System.Windows.Forms.Cursor]::Position).x $y=([System.Windows.Forms.Cursor]::Position).y $positions=[Text.Encoding]::ASCII.GetBytes($x.ToString()+','+$y.ToString()) #Send position x,y $UdpClient=New-Object System.Net.Sockets.UdpClient $UdpClient.Send($positions,$positions.Length,$IPEndPoint) $UdpClient.Close() |