Ejemplo n.º 1
0
    static void createGetDelegate(InputTypeMethod m)
    {
#if UNITY_WEBPLAYER
        touchCountFunc = () => MouseSim.touchCount;
        touchesFunc    = () => MouseSim.touches;
        GetTouchFunc   = (int i) => MouseSim.GetTouch(i);
#elif NETFX_CORE
        TypeInfo t = Type.GetType(m.ObjectName + "," + m.AssemblyName).GetTypeInfo();

        PropertyInfo p = t.GetDeclaredProperty("touches");
        touchesFunc = (Func <Touch[]>)p.GetMethod.CreateDelegate(typeof(Func <Touch[]>));

        PropertyInfo pT = t.GetDeclaredProperty("touchCount");
        touchCountFunc = (Func <int>)pT.GetMethod.CreateDelegate(typeof(Func <int>));

        MethodInfo mInfo = t.GetDeclaredMethod("GetTouch");
        GetTouchFunc = (Func <int, Touch>)mInfo.CreateDelegate(typeof(Func <int, Touch>));
#else
        Assembly b = Assembly.Load(m.AssemblyName);
        Type     t = b.GetType(m.ObjectName, true);

        PropertyInfo p = t.GetProperty("touches");
        touchesFunc = (Func <Touch[]>)Delegate.CreateDelegate(typeof(Func <Touch[]>), p.GetGetMethod());

        PropertyInfo pT = t.GetProperty("touchCount");
        touchCountFunc = (Func <int>)Delegate.CreateDelegate(typeof(Func <int>), pT.GetGetMethod());

        MethodInfo mInfo = t.GetMethod("GetTouch");
        GetTouchFunc = (Func <int, Touch>)Delegate.CreateDelegate(typeof(Func <int, Touch>), mInfo);
#endif
    }
Ejemplo n.º 2
0
        public override async Task MoveMouse(IAsyncStreamReader <MouseCoords> coordsStream, IServerStreamWriter <Response> responseStream, ServerCallContext context)
        {
            while (await coordsStream.MoveNext())
            {
                var coords = coordsStream.Current;

                if (coords.Y == 0 && coords.X == 0)
                {
                    InitialMouseCoords = PlatformControls.GetCursorPosition();
                }

                Console.WriteLine("Moving mouse to: " + coords.X + "," + coords.Y);

                var x = InitialMouseCoords.X + coords.X;
                var y = InitialMouseCoords.Y + coords.Y;

                // MouseSim.MoveMouseTo(x, y);
                int sensitivity = 3;
                MouseSim.MoveMouseBy((coords.X * -1) / sensitivity, (coords.Y * -1) / sensitivity);
                // MouseSim.MoveMouseToPositionOnVirtualDesktop(coords.X, coords.Y);

                Response reply = new Response {
                    Received = true
                };
                await responseStream.WriteAsync(reply);
            }
        }
Ejemplo n.º 3
0
        public override async Task PressKey(IAsyncStreamReader <Key> keyStream, IServerStreamWriter <Response> responseStream, ServerCallContext context)
        {
            while (await keyStream.MoveNext())
            {
                var key  = keyStream.Current;
                var keys = new VirtualKeyCode[] { (VirtualKeyCode)key.FirstId, key.SecondId == 0 ? (VirtualKeyCode)key.SecondId : 0 };
                foreach (var k in keys)
                {
                    if (k != 0 && (ushort)k != 0x9001) // Not a blank key
                    {
                        if (k == VirtualKeyCode.CANCEL)
                        {
                            foreach (var downKey in CurrentKeys)
                            {
                                KeyboardSim.KeyUp(downKey);
                                if (downKey == VirtualKeyCode.LBUTTON)
                                {
                                    MouseSim.LeftButtonUp();
                                }
                                else if (downKey == VirtualKeyCode.RBUTTON)
                                {
                                    MouseSim.RightButtonUp();
                                }
                            }
                            CurrentKeys.Clear();
                        }
                        else if (k == VirtualKeyCode.VK_W || k == VirtualKeyCode.VK_A || k == VirtualKeyCode.VK_S || k == VirtualKeyCode.VK_D) // Directional, Mouse keys
                        {
                            if (CurrentKeys.Count > 1)
                            {
                                foreach (var downKey in CurrentKeys)
                                {
                                    KeyboardSim.KeyUp(downKey);
                                }
                                CurrentKeys.Clear();
                            }
                            CurrentKeys.Add(k);
                            KeyboardSim.KeyDown(k);
                        }
                        else if (k == VirtualKeyCode.LBUTTON)
                        {
                            MouseSim.LeftButtonDown();
                            CurrentKeys.Add(k);
                        }
                        else if (k == VirtualKeyCode.RBUTTON)
                        {
                            MouseSim.RightButtonDown();
                            CurrentKeys.Add(k);
                        }
                        else // Treat as a button
                        {
                            // If HOLD enabled, just keydown, await key up
                            // IF HOLD disabled, just a keypress
                            if (Settings.BUTTON_TOGGLE)
                            {
                                KeyboardSim.KeyPress(k);
                            }
                            else // HOLD
                            {
                                CurrentKeys.Add(k);
                                KeyboardSim.KeyDown(k);
                            }
                        }
                    }
                }

                if (CurrentKeys.Count > 0)
                {
                    Console.WriteLine(string.Join(",", CurrentKeys.ToArray()));
                }

                Response reply = new Response {
                    Received = true
                };
                await responseStream.WriteAsync(reply);
            }
        }