private ControllerIdType InitializeDevice(InputDeviceAccess.TypeOfDevices TypeOfDevice, System.Collections.Hashtable NewKeyTable) { InputDeviceAccess CurrDevice = null; ControllerIdType NewControllerId = new ControllerIdType(); //If the desired device is a keyboard and another keyboard has available users // assign this user to the same keyboard. if (TypeOfDevice == InputDeviceAccess.TypeOfDevices.Keyboard) { foreach (InputDeviceAccess ExistingDevice in this.Devices) { if (ExistingDevice.TypeOfDevice == InputDeviceAccess.TypeOfDevices.Keyboard && ExistingDevice.DeviceUserCount < ExistingDevice.DeviceUserMax) { CurrDevice = ExistingDevice; } } } //create device if (CurrDevice == null) { CurrDevice = new InputDeviceAccess(this.ParentForm, TypeOfDevice); } //controller info: guid & device user id NewControllerId.DeviceGuid = CurrDevice.Guid; NewControllerId.DeviceUserId = CurrDevice.GetNextUserId(); //Save ControllerId and Device this.ControllerIds.Add(NewControllerId); this.Devices.Add(CurrDevice); //Send device new keytable CurrDevice.SetKeyTable(NewKeyTable, NewControllerId.DeviceUserId); //Poll the device to give it some keys to check CurrDevice.PollInput(); return(NewControllerId); }
public InputDeviceAccess GetInputDeviceRef(ControllerIdType ControllerWithGuidOfDeviceToReturn) { InputDeviceAccess DeviceToReturn = null; //Find the device with the guid and returns a reference to it foreach (InputDeviceAccess CurrInputDevice in this.Devices) { if (CurrInputDevice.Guid == ControllerWithGuidOfDeviceToReturn.DeviceGuid) { DeviceToReturn = CurrInputDevice; } } //Throw if the device was not found if (DeviceToReturn == null) { throw new System.Exception("the device manager was instructed to return a reference to a device with the Guid " + ControllerWithGuidOfDeviceToReturn.DeviceGuid.ToString() + " which is not an existing device"); } return(DeviceToReturn); }