0

I've made a program were I can control a linux computer (In this case, a raspberry pi) running my Receiver script (Python). So far, I'm able to send nearly all characters, letters and numbers to it. Problem is, the mouse movement. Right now I'm using the NUMPAD to control the mousemovement, but it's slow and it can only move +x or +y, not both.

So I'm wondering if I could somehow freeze my mouse position in the program and when I try to move the mouse, it will send the mouse movement changes. Meaning that if I where to drag the mouse, it would send something like "MOUSE(+10, -4)" in UDP packet. I don't want it to spam the Receiver.py with UDP packets, so I guess a little timer would be nice. I'm mostly wondering about how I would be able to freeze the mouse while it being functioning in the program.

Here is the code I'm using to send numbers, symbols and letters:

if (piCheck.Checked) //As long as this is checked, every letter and mousemovement should be sent.
{
        try
        {
                Socket sock = new Socket(AddressFamily.InterNetwork, SocketType.Dgram, ProtocolType.Udp);

                string IpAddress = textBox1.Text;
                IPAddress serverAddr = IPAddress.Parse(IpAddress);


                IPEndPoint endPoint = new IPEndPoint(serverAddr, _PORT);

                byte[] send_buffer = UTF8Encoding.UTF8.GetBytes(e.KeyCode.ToString());

                sock.SendTo(send_buffer, endPoint);
                textinfo.Text = "It's fine...? Yea it is.";
        }

        catch (System.FormatException)
        {
                textinfo.Text = "SENDING ERROR";
        }
}

Yes, I have a lot more to the code than that, including Upper keys, CTRL, SHIFT etc..

You probably don't know much about Python, but here is some of the code:

######MOUSE######
elif data == 'NumPad8':
    os.system("xte 'mousermove 0 -6'")
elif data == 'NumPad6':
    os.system("xte 'mousermove 6 0'")
elif data == 'NumPad5':
    os.system("xte 'mousermove 0 6'")
elif data == 'NumPad4':
    os.system("xte 'mousermove -6 0'")
elif data == 'NumPad0':
    os.system("xte 'mouseclick 1'")
elif data == 'CTRLNumPad0':
    os.system("xte 'keydown Control_L' 'mouseclick 1' 'keyup Control_L'")
elif data == 'Insert':
    os.system("xte 'keydown Shift_L' 'mouseclick 1' 'keyup Shift_L'")
elif data == 'Decimal':
    os.system("xte 'mouseclick 3'")
elif data == 'Subtract':
    os.system("xte 'mouseclick 4'")
elif data == 'Add':
    os.system("xte 'mouseclick 5'")

It uses the extension Xautomation. (sudo apt-get install xautomation)

Please help.

KrisPus
  • 53
  • 2
  • 13
  • Are you sending system-wide mouse movements from a C# program to the receiver program ? Can you post some of the code where you are doing this ? – Arctic Vowel Aug 22 '16 at 04:13
  • 1
    Edited the question, see if it makes it easier. I haven't started on the mouse movement. – KrisPus Aug 22 '16 at 04:32
  • Yes that's much clearer now. Also, is this a C# console application or is it winforms / wpf ? – Arctic Vowel Aug 22 '16 at 04:43
  • Please see http://stackoverflow.com/questions/5528543/getting-position-of-mouse-cursor-when-clicked-out-side-the-forms-boundary – Arctic Vowel Aug 22 '16 at 04:46
  • @AniruddhaVarma It is c# Windows Form. Here is a screenshot [Imgur 44WfgTh.png](http://i.imgur.com/44WfgTh.png) – KrisPus Aug 22 '16 at 05:04
  • @AniruddhaVarma Yes that link does display mouse position, but I don't know how I would be able to Freeze the mouse in my application while sending the new position to the Receiver.py. – KrisPus Aug 22 '16 at 05:05
  • You can't freeze the mouse to the best of my knowledge. Why do that, you could just store the cursor positions in a `List` and send them one by one, maybe with a timer as you describe. – Arctic Vowel Aug 22 '16 at 05:12
  • And there is no way to set the mouse position manually? – KrisPus Aug 22 '16 at 05:35
  • Yes you can, please see http://stackoverflow.com/questions/8050825/how-to-move-mouse-cursor-using-c – Arctic Vowel Aug 22 '16 at 06:15

0 Answers0