Example #1
0
		public static IOHIDValue FromInteger (IOHIDElement element, int value)
		{
			var timeStamp = Time.Absolute;
			var valueRef = IOHIDValueCreateWithIntegerValue (IntPtr.Zero,
			                                                 element.Handle,
			                                                 timeStamp,
			                                                 (CFIndex)value);
			return new IOHIDValue (valueRef, true);
		}
Example #2
0
		public static IOHIDValue FromBytes (IOHIDElement element, byte[] bytes)
		{
			var timeStamp = Time.Absolute;
			var valueRef = IOHIDValueCreateWithBytes (IntPtr.Zero,
			                                          element.Handle,
			                                          timeStamp, bytes,
			                                          (CFIndex)bytes.Length);
			return new IOHIDValue (valueRef, true);
		}
Example #3
0
		public void Detatch (IOHIDElement element) {
			ThrowIfDisposed ();
			if (element == null)
				throw new ArgumentNullException ("element");
			IOHIDElementDetach (Handle, element.Handle);
		}
Example #4
0
		public IDictionary<IOHIDElement, IOHIDValue> GetValues (IOHIDElement[] elements) {
			ThrowIfDisposed ();
			if (elements == null)
				throw new ArgumentNullException ("elements");
			var elementArray = CFArray.FromNativeObjects (elements);
			IOHIDElement[] keys = new IOHIDElement[elements.Length];
			IOHIDValue[] values = new IOHIDValue[elements.Length];
			CFDictionary multiple = CFDictionary.FromObjectsAndKeys (values, keys);
			var multipleRef = multiple.Handle;
			var result = IOHIDDeviceCopyValueMultiple (Handle, elementArray.Handle, ref multipleRef);
			IOObject.ThrowIfError (result);
			var dict = new Dictionary<IOHIDElement, IOHIDValue> (multiple.Count);
			IntPtr[] keyRefs, valueRefs;
			multiple.GetKeysAndValues (out keyRefs, out valueRefs);
			for (int i = 0; i < multiple.Count; i++)
				dict.Add (new IOHIDElement (keyRefs [i], true), new IOHIDValue (valueRefs [i], true));
			CFType.Release (multiple.Handle);
			return dict;
		}
Example #5
0
		public IOHIDValue GetValue (IOHIDElement element) {
			ThrowIfDisposed ();
			if (element == null)
				throw new ArgumentNullException ("element");
			IntPtr valueRef;
			var result = IOHIDDeviceGetValue (Handle, element.Handle, out valueRef);
			IOObject.ThrowIfError (result);
			if (valueRef == IntPtr.Zero)
				return null;
			return new IOHIDValue (valueRef, true);
		}
Example #6
0
		public void SetValue (IOHIDElement element, IOHIDValue value) {
			ThrowIfDisposed ();
			if (element == null)
				throw new ArgumentNullException ("element");
			if (value == null)
				throw new ArgumentNullException ("value");
			var result = IOHIDDeviceSetValue (Handle, element.Handle, value.Handle);
			IOObject.ThrowIfError (result);
		}
Example #7
0
		public IOHIDElement[] GetAllElements () {
			ThrowIfDisposed ();
			var arrayRef = IOHIDDeviceCopyMatchingElements (Handle, IntPtr.Zero, 0);
			if (arrayRef == IntPtr.Zero)
				return null;
			using (var array = new CFArray (arrayRef, true)) {
				var elements = new IOHIDElement[array.Count];
				for (int i = 0; i < elements.Length; i++)
					elements [i] = new IOHIDElement (array.GetValue (i), true);
				return elements;
			}
		}
Example #8
0
		public IOHIDElement[] GetMatchingElements (IDictionary<string, ValueType> matchingDictionary) {
			ThrowIfDisposed ();
			if (matchingDictionary == null)
				throw new ArgumentNullException ("matchingDictionary");
			var matching = NSDictionary.FromObjectsAndKeys (matchingDictionary.Values.ToArray (),
			                                                matchingDictionary.Keys.ToArray ());
			var arrayRef = IOHIDDeviceCopyMatchingElements (Handle, matching.Handle, 0);
			if (arrayRef == IntPtr.Zero)
				return null;
			using (var array = new CFArray (arrayRef, true)) {
				var elements = new IOHIDElement[array.Count];
				for (int i = 0; i < elements.Length; i++)
					elements [i] = new IOHIDElement(array.GetValue (i), true);
				return elements;
			}
		}