Exemplo n.º 1
0
        /// <summary>
        /// Function to create a keyboard interface.
        /// </summary>
        /// <param name="window">Window to bind with.</param>
        /// <param name="keyboardName">The name of the keyboard to use.</param>
        /// <returns>A new keyboard interface.</returns>
        /// <remarks>Passing an empty string for <paramref name="keyboardName"/> will use the system keyboard (i.e. data from all keyboards will be tracked by the same interface).
        /// <para>Pass NULL to the <paramref name="window"/> parameter to use the <see cref="P:GorgonLibrary.Gorgon.ApplicationForm">Gorgon application form</see>.</para>
        /// </remarks>
        /// <exception cref="System.Collections.Generic.KeyNotFoundException">Thrown when a keyboard with the <paramref name="keyboardName"/> could not be found.</exception>
        public GorgonKeyboard CreateKeyboard(Control window, string keyboardName)
        {
            GorgonInputDeviceInfo deviceInfo = null;

            if ((!string.IsNullOrWhiteSpace(keyboardName)) && (!KeyboardDevices.TryGetValue(keyboardName, out deviceInfo)))
            {
                throw new ArgumentException(string.Format(Resources.GORINP_KEYBOARD_NOT_FOUND, keyboardName), "keyboardName");
            }

            var keyboardDevice = GetInputDevice <GorgonKeyboard>(deviceInfo);

            if (keyboardDevice == null)
            {
                keyboardDevice            = CreateKeyboardImpl(window, deviceInfo);
                keyboardDevice.DeviceType = InputDeviceType.Keyboard;
                keyboardDevice.UUID       = GetDeviceUUID(deviceInfo, keyboardDevice.GetType());
                Devices.Add(keyboardDevice.UUID, keyboardDevice);
            }

            keyboardDevice.GetDefaultKeyMapping();
            keyboardDevice.KeyStateResetMode = KeyStateResetMode.ResetAll;
            keyboardDevice.KeyStates.Reset();
            keyboardDevice.Bind(window);
            keyboardDevice.Enabled   = true;
            keyboardDevice.Exclusive = (ExclusiveDevices & InputDeviceType.Keyboard) == InputDeviceType.Keyboard;

            return(keyboardDevice);
        }
Exemplo n.º 2
0
        /// <summary>
        /// Function to retrieve the factory UUID for the device.
        /// </summary>
        /// <param name="name">Name of the device.</param>
        /// <param name="deviceType">Type of input device.</param>
        /// <returns>The UUID for the device.</returns>
        private static string GetDeviceUUID(GorgonInputDeviceInfo name, Type deviceType)
        {
            string result = Guid.Empty.ToString();

            if (name != null)
            {
                result = name.UUID.ToString();
            }

            result += "_" + deviceType.FullName;

            return(result);
        }
Exemplo n.º 3
0
        /// <summary>
        /// Function to retrieve an existing input device.
        /// </summary>
        /// <typeparam name="T">Type name of the device.</typeparam>
        /// <param name="name">Name of the device.</param>
        /// <returns>The input device if it was previously created, NULL (Nothing in VB.Net) if not.</returns>
        private T GetInputDevice <T>(GorgonInputDeviceInfo name) where T : GorgonInputDevice
        {
            Type   devType = typeof(T);
            string uuid    = GetDeviceUUID(name, devType);

            if (!Devices.ContainsKey(uuid))
            {
                return(null);
            }

            var device = Devices[uuid] as T;

            if (device == null)
            {
                throw new ArgumentException(string.Format(Resources.GORINP_DEVICE_ALREADY_EXISTS_TYPE_MISMATCH, devType.FullName), "name");
            }

            return(device);
        }
Exemplo n.º 4
0
        /// <summary>
        /// Function to create a pointing device interface.
        /// </summary>
        /// <param name="window">Window to bind with.</param>
        /// <param name="pointingDeviceName">The name of the pointing device to use.</param>
        /// <returns>A new pointing device interface.</returns>
        /// <remarks>Passing an empty string for <paramref name="pointingDeviceName"/> will use the system pointing device (i.e. data from all pointing devices will be tracked by the same interface).
        /// <para>Pass NULL to the <paramref name="window"/> parameter to use the <see cref="P:GorgonLibrary.Gorgon.ApplicationForm">Gorgon application form</see>.</para>
        /// </remarks>
        /// <exception cref="System.Collections.Generic.KeyNotFoundException">Thrown when a pointing device with the <paramref name="pointingDeviceName"/> could not be found.</exception>
        public GorgonPointingDevice CreatePointingDevice(Control window, string pointingDeviceName)
        {
            GorgonInputDeviceInfo deviceInfo = null;

            if ((!string.IsNullOrWhiteSpace(pointingDeviceName)) && (!PointingDevices.TryGetValue(pointingDeviceName, out deviceInfo)))
            {
                throw new ArgumentException(string.Format(Resources.GORINP_POINTINGDEVICE_NOT_FOUND, pointingDeviceName), "pointingDeviceName");
            }

            // Only reset this once.
            if (!Devices.Any(item => item.Value is GorgonPointingDevice))
            {
                GorgonPointingDevice.ResetCursor();
            }

            var pointingDevice = GetInputDevice <GorgonPointingDevice>(deviceInfo);

            if (pointingDevice == null)
            {
                pointingDevice            = CreatePointingDeviceImpl(window, deviceInfo);
                pointingDevice.DeviceType = InputDeviceType.PointingDevice;
                pointingDevice.UUID       = GetDeviceUUID(deviceInfo, pointingDevice.GetType());
                Devices.Add(pointingDevice.UUID, pointingDevice);
            }

            // Default to the last position for the mouse cursor.
            pointingDevice.Position      = window.PointToClient(Cursor.Position);
            pointingDevice.PositionRange = RectangleF.Empty;
            pointingDevice.WheelRange    = Point.Empty;
            pointingDevice.ResetButtons();
            pointingDevice.Bind(window);
            pointingDevice.Enabled   = true;
            pointingDevice.Exclusive = (ExclusiveDevices & InputDeviceType.PointingDevice) == InputDeviceType.PointingDevice;

            if (!pointingDevice.Exclusive)
            {
                pointingDevice.ShowCursor();
            }

            return(pointingDevice);
        }
Exemplo n.º 5
0
 /// <summary>
 /// Function to create a custom HID interface.
 /// </summary>
 /// <param name="window">Window to bind with.</param>
 /// <param name="hidInfo">A <see cref="GorgonLibrary.Input.GorgonInputDeviceInfo">GorgonDeviceName</see> object containing the HID information.</param>
 /// <returns>A new custom HID interface.</returns>
 /// <remarks>Implementors must implement this method if they wish to return data from a undefined (custom) device.
 /// <para>Pass NULL to the <paramref name="window"/> parameter to use the <see cref="P:GorgonLibrary.Gorgon.ApplicationForm">Gorgon application form</see>.</para>
 /// </remarks>
 /// <exception cref="System.ArgumentNullException">The <paramRef name="hidInfo"/> is NULL.</exception>
 protected abstract GorgonCustomHID CreateCustomHIDImpl(Control window, GorgonInputDeviceInfo hidInfo);
Exemplo n.º 6
0
 /// <summary>
 /// Function to create a joystick interface.
 /// </summary>
 /// <param name="window">Window to bind with.</param>
 /// <param name="joystickInfo">A <see cref="GorgonLibrary.Input.GorgonInputDeviceInfo">GorgonDeviceName</see> object containing the joystick information.</param>
 /// <returns>A new joystick interface.</returns>
 /// <remarks>Pass NULL to the <paramref name="window"/> parameter to use the <see cref="P:GorgonLibrary.Gorgon.ApplicationForm">Gorgon application form</see>.</remarks>
 /// <exception cref="System.ArgumentNullException">The <paramRef name="joystickInfo"/> is NULL.</exception>
 protected abstract GorgonJoystick CreateJoystickImpl(Control window, GorgonInputDeviceInfo joystickInfo);
Exemplo n.º 7
0
 /// <summary>
 /// Function to create a pointing device interface.
 /// </summary>
 /// <param name="window">Window to bind with.</param>
 /// <param name="pointingDeviceInfo">Name of the pointing device device to create.</param>
 /// <returns>A new pointing device interface.</returns>
 /// <remarks>Passing NULL for <paramref name="pointingDeviceInfo"/> will use the system pointing device.
 /// <para>Pass NULL to the <paramref name="window"/> parameter to use the <see cref="P:GorgonLibrary.Gorgon.ApplicationForm">Gorgon application form</see>.</para>
 /// </remarks>
 protected abstract GorgonPointingDevice CreatePointingDeviceImpl(Control window, GorgonInputDeviceInfo pointingDeviceInfo);
Exemplo n.º 8
0
        // ReSharper restore InconsistentNaming

        /// <summary>
        /// Function to create a keyboard interface.
        /// </summary>
        /// <param name="window">Window to bind with.</param>
        /// <param name="keyboardInfo">Name of the keyboard device to create.</param>
        /// <returns>A new keyboard interface.</returns>
        /// <remarks>Passing NULL for <paramref name="keyboardInfo"/> will use the system keyboard.
        /// <para>Pass NULL to the <paramref name="window"/> parameter to use the <see cref="P:GorgonLibrary.Gorgon.ApplicationForm">Gorgon application form</see>.</para></remarks>
        protected abstract GorgonKeyboard CreateKeyboardImpl(Control window, GorgonInputDeviceInfo keyboardInfo);