Esempio n. 1
0
        private void AddKeyboardDevices(IntPtr windowHandle)
        {
            DeviceList keyboardControllerList = Manager.GetDevices(DeviceClass.Keyboard, EnumDevicesFlags.AttachedOnly);

            for (int i = 0; i < keyboardControllerList.Count; i++)
            {
                keyboardControllerList.MoveNext();
                DeviceInstance deviceInstance = (DeviceInstance)keyboardControllerList.Current;

                Device device = new Device(deviceInstance.InstanceGuid);

                if (!CheckIfDirectInputDeviceExists(device))
                {
                    device.SetCooperativeLevel(windowHandle, CooperativeLevelFlags.Background | CooperativeLevelFlags.NonExclusive);
                    device.SetDataFormat(DeviceDataFormat.Keyboard);
                    device.Acquire();

                    KeyboardInput input = new KeyboardInput(device);
                    AddInputDevice(input);
                    input.InitCurrentlyInvokedInput();

                    InvokeNewInputDeviceEvent(input.DeviceInstanceId, input);
                }
            }
        }
Esempio n. 2
0
        private void AddNewDevices()
        {
            List <GenericInput> newDevices = new List <GenericInput>();

            newDevices.AddRange(KeyboardInput.GetNewInputDevices(windowHandle, inputDevices));
            newDevices.AddRange(JoystickInput.GetNewInputDevices(windowHandle, inputDevices));
            newDevices.AddRange(WiiMoteInput.GetNewInputDevices(windowHandle, inputDevices));
            //newDevices.AddRange(SpeechInput.GetNewInputDevices(windowHandle, inputDevices));

            foreach (GenericInput inputDevice in newDevices)
            {
                AddInputDevice(inputDevice);
                InitInputDevice(inputDevice);
            }
        }
        public static List<GenericInput> GetNewInputDevices(IntPtr windowHandle, List<GenericInput> currentDevices)
        {
            List<GenericInput> newDevices = new List<GenericInput>();

            DeviceList keyboardControllerList = Manager.GetDevices(DeviceClass.Keyboard, EnumDevicesFlags.AttachedOnly);
            for (int i = 0; i < keyboardControllerList.Count; i++)
            {
                keyboardControllerList.MoveNext();
                DeviceInstance deviceInstance = (DeviceInstance)keyboardControllerList.Current;

                Device device = new Device(deviceInstance.InstanceGuid);

                if (!CheckIfDirectInputDeviceExists(device, currentDevices))
                {
                    AcquireDirectInputDevice(windowHandle, device, DeviceDataFormat.Keyboard);
                    KeyboardInput input = new KeyboardInput(device);

                    newDevices.Add(input);
                }
            }

            return newDevices;
        }
        public static List <GenericInput> GetNewInputDevices(IntPtr windowHandle, List <GenericInput> currentDevices)
        {
            List <GenericInput> newDevices = new List <GenericInput>();

            DeviceList keyboardControllerList = Manager.GetDevices(DeviceClass.Keyboard, EnumDevicesFlags.AttachedOnly);

            for (int i = 0; i < keyboardControllerList.Count; i++)
            {
                keyboardControllerList.MoveNext();
                DeviceInstance deviceInstance = (DeviceInstance)keyboardControllerList.Current;

                Device device = new Device(deviceInstance.InstanceGuid);

                if (!CheckIfDirectInputDeviceExists(device, currentDevices))
                {
                    AcquireDirectInputDevice(windowHandle, device, DeviceDataFormat.Keyboard);
                    KeyboardInput input = new KeyboardInput(device);

                    newDevices.Add(input);
                }
            }

            return(newDevices);
        }
        private void AddKeyboardDevices(IntPtr windowHandle)
        {
            DeviceList keyboardControllerList = Manager.GetDevices(DeviceClass.Keyboard, EnumDevicesFlags.AttachedOnly);
            for (int i = 0; i < keyboardControllerList.Count; i++)
            {
                keyboardControllerList.MoveNext();
                DeviceInstance deviceInstance = (DeviceInstance)keyboardControllerList.Current;

                Device device = new Device(deviceInstance.InstanceGuid);

                if (!CheckIfDirectInputDeviceExists(device))
                {
                    device.SetCooperativeLevel(windowHandle, CooperativeLevelFlags.Background | CooperativeLevelFlags.NonExclusive);
                    device.SetDataFormat(DeviceDataFormat.Keyboard);
                    device.Acquire();

                    KeyboardInput input = new KeyboardInput(device);
                    AddInputDevice(input);
                    input.InitCurrentlyInvokedInput();

                    InvokeNewInputDeviceEvent(input.DeviceInstanceId, input);
                }
            }
        }