Пример #1
0
        public bool Destroy()
        {
            if (!Created)
            {
                return(true);
            }
            // destroy devices
            foreach (var pair in deviceHandles)
            {
                switch (pair.Key.DeviceType)
                {
                case VirtualDeviceType.Keyboard:
                    Ivj.DisconnectKeyboard(contextHandle, pair.Value);
                    break;

                case VirtualDeviceType.TrackingInterface:
                    Ivj.DisconnectFreetrackInterface(contextHandle, pair.Value);
                    break;

                default:
                    throw new NotImplementedException();
                    // TODO: implement missing cases
                }
            }
            deviceHandles.Clear();
            bool result = Ivj.DestroyContext(contextHandle);

            contextHandle = IntPtr.Zero;
            return(result);
        }
Пример #2
0
        public bool DisconnectDevice(IVirtualDevice device)
        {
            if (device == null)
            {
                throw new ArgumentNullException("device");
            }
            if (!Created)
            {
                return(false);
            }
            IntPtr handle;

            if (!deviceHandles.TryGetValue(device, out handle))
            {
                return(true);
            }
            switch (device.DeviceType)
            {
            case VirtualDeviceType.Keyboard:
                Ivj.DisconnectKeyboard(contextHandle, handle);
                break;

            case VirtualDeviceType.TrackingInterface:
                Ivj.DisconnectFreetrackInterface(contextHandle, handle);
                break;

            default:
                throw new NotImplementedException();
            }
            deviceHandles.Remove(device);
            return(true);
        }
Пример #3
0
 public bool Create()
 {
     if (contextHandle != IntPtr.Zero)
     {
         return(true);
     }
     contextHandle = Ivj.CreateContext();
     return(contextHandle != IntPtr.Zero);
 }
Пример #4
0
        private bool SendFreetrackInterface(IVirtualDevice device, IntPtr handle)
        {
            object[] modifiedKeys = device.GetModifiedKeys(VirtualDeviceCapability.Axis);
            foreach (object key in modifiedKeys)
            {
                KeyState state     = device.GetKeyState(VirtualDeviceCapability.Axis, key);
                int      axisIndex = Ivj.GetFreetrackAxisIndex(key);
                if (axisIndex > -1)
                {
                    Ivj.SetFreetrackAxis(handle, axisIndex, state.SmoothAxis, state.RawAxis);
                }
            }
            bool result = Ivj.SendFreetrackInterface(handle);

            device.Send();
            return(result);
        }
Пример #5
0
        private bool SendKeyboard(IVirtualDevice device, IntPtr handle)
        {
            object[] modifiedKeys = device.GetModifiedKeys(VirtualDeviceCapability.Key);
            foreach (object key in modifiedKeys)
            {
                KeyState state    = device.GetKeyState(VirtualDeviceCapability.Key, key);
                int      keyIndex = Ivj.GetKeyboardKeyIndex(key);
                if (keyIndex > -1)
                {
                    Ivj.SetKeyboardKey(handle, keyIndex, state.SmoothPressed);
                }
            }
            bool result = Ivj.SendKeyboard(handle);

            device.Send();
            return(result);
        }
Пример #6
0
        public bool ConnectDevice(IVirtualDevice device)
        {
            if (device == null)
            {
                throw new ArgumentNullException("device");
            }
            if (!Created)
            {
                return(false);
            }
            if (deviceHandles.ContainsKey(device))
            {
                return(true);
            }
            IntPtr handle = IntPtr.Zero;
            IntPtr constructionInfo;

            switch (device.DeviceType)
            {
            case VirtualDeviceType.Keyboard:
                constructionInfo = Ivj.AllocKeyboardConstructionInfo();
                handle           = Ivj.ConnectKeyboard(contextHandle, constructionInfo);
                Ivj.FreeKeyboardConstructionInfo(constructionInfo);
                break;

            case VirtualDeviceType.TrackingInterface:
                constructionInfo = Ivj.AllocFreetrackConstructionInfo();
                handle           = Ivj.ConnectFreetrackInterface(contextHandle, constructionInfo);
                Ivj.FreeFreetrackConstructionInfo(constructionInfo);
                break;

            default:
                throw new NotImplementedException();
            }
            if (handle == IntPtr.Zero)
            {
                return(false);
            }
            deviceHandles.Add(device, handle);
            return(true);
        }