private static IHeaderArray Create <TValue>(JObject jObject, HeaderArrayType type) where TValue : IEquatable <TValue> { IEnumerable <KeyValuePair <string, IImmutableList <string> > > sets = ParseSets(jObject["Sets"]); IEnumerable <KeyValuePair <KeySequence <string>, TValue> > entries = ParseEntries(jObject["Entries"]); IImmutableSequenceDictionary <string, TValue> sequenceDictionary = new ImmutableSequenceDictionary <string, TValue>(sets, entries); return (new HeaderArray <TValue>( jObject["Header"].Value <string>(), jObject["Coefficient"].Value <string>(), jObject["Description"].Value <string>(), type, jObject["Dimensions"].Values <int>().ToImmutableArray(), sequenceDictionary)); IEnumerable <KeyValuePair <KeySequence <string>, TValue> > ParseEntries(JToken jsonEntries) { return (JsonConvert.DeserializeObject <IDictionary <string, TValue> >(jsonEntries.ToString()) .Select( x => new KeyValuePair <KeySequence <string>, TValue>( KeySequence <string> .Parse(x.Key), x.Value))); } IEnumerable <KeyValuePair <string, IImmutableList <string> > > ParseSets(JToken jsonSets) { return (jsonSets.Values <JToken>() .Select( x => new KeyValuePair <string, IImmutableList <string> >( x.Value <string>("Key"), x.Value <JArray>("Value") .Values <string>() .ToImmutableArray()))); } }
private void HandleHeadMovement(object sender, HeadMovementEventArgs e) { String gesture = e.Gesture; if (gesture.Equals(Gesture.Pitch.Down)) { // reserve this gesture for mouse clicks uint x = (uint)System.Windows.Forms.Cursor.Position.X; uint y = (uint)System.Windows.Forms.Cursor.Position.Y; mouse_event(MOUSEEVENTF_LEFTDOWN | MOUSEEVENTF_LEFTUP, x, y, 0, 0); } else { // get window title IntPtr handle = GetForegroundWindow(); int length = GetWindowTextLength(handle) + 1; StringBuilder title = new StringBuilder(length); GetWindowText(handle, title, title.Capacity); // get processes Process[] pl = Process.GetProcesses(); foreach (Process p in pl) { // find the process for the active window if (p.MainWindowHandle == handle) { Dictionary <String, String> map = Settings.Instance.HeadMovement.GetMapping(p.ProcessName); if (map != null) { String sequence = map[gesture]; SendKeys.SendWait(keySequence.Parse(sequence)); } } } } }