コード例 #1
0
        public Tuple <bool, bool> IsAllPressed(BindingsFile.Assignment a)     // return if all okay pressed, second if all are pressable
        {
            bool allpressable = true;

            foreach (BindingsFile.DeviceKeyPair ma in a.keys)
            {
                InputDeviceInterface idi = GetInputDeviceFromBindingDevice(ma.Device);

                if (idi == null)        // no device, false
                {
                    return(new Tuple <bool, bool>(false, false));
                }

                bool?v = idi.IsPressed(ma.Key); // is it pressed, or not pressable?

                if (v.HasValue)                 // is pressable
                {
                    if (v.Value == false)       // if it
                    {
                        return(new Tuple <bool, bool>(false, false));
                    }
                }
                else
                {
                    allpressable = false;   // not pressable
                }
            }

            return(new Tuple <bool, bool>(true, allpressable));
        }
コード例 #2
0
        private void Devices_OnNewEvent(List <InputDeviceEvent> list)
        {
            IntPtr handle = GetForegroundWindow();

            Process[] processes = Process.GetProcessesByName("elitedangerous64");//Process.GetProcessesByName("EliteDangerous64");
            bool      ed        = false;

            foreach (Process p in processes)
            {
                if (p.MainWindowHandle == handle)       //ED seems to have multiple processes running.. find one
                {
                    ed = true;
                    break;
                }
            }

            if (!ed)
            {
                //System.Diagnostics.Debug.WriteLine("Rejected keypress " + processes.Length);
                return;
            }

            foreach (InputDeviceEvent je in list)
            {
                string match = je.EventName();              // same as bindings name..
                System.Diagnostics.Debug.WriteLine(je.ToString(10) + " " + match);

                ac.ActionRun("onEliteInputRaw", "EliteUIEvent", additionalvars: new Conditions.ConditionVariables(new string[]
                                                                                                                  { "Device", je.Device.ID().Name, "EventName", match, "Pressed", je.Pressed?"1":"0", "Value", je.Value.ToStringInvariant() }));

                BindingsFile.Device dv = GetBindingDeviceFromInputDeviceIdentifier(je.Device.ID());

                if (dv != null)
                {
                    List <BindingsFile.Assignment> assignlist = dv.Find(match, false);       // get everything associated with this key..

                    if (assignlist != null)
                    {
                        List <BindingsFile.Assignment> inonstate = new List <BindingsFile.Assignment>();
                        List <bool> ispressable = new List <bool>();

                        foreach (BindingsFile.Assignment a in assignlist)
                        {
                            Tuple <bool, bool> pressstate = IsAllPressed(a);
                            if (pressstate.Item1)       // if pressed
                            {
                                //System.Diagnostics.Debug.WriteLine("  Rule Matches " + a.assignedfunc);
                                inonstate.Add(a);       // but it might not be the best rule..
                                ispressable.Add(pressstate.Item2);
                            }
                            else
                            {
                                int isonindex = assignmentsinonstate.IndexOf(a);
                                if (isonindex != -1)
                                {
                                    System.Diagnostics.Debug.WriteLine("Action " + a.assignedfunc + "-");
                                    assignmentsinonstate.Remove(a);
                                    ac.ActionRun("onEliteInputOff", "EliteUIEvent", additionalvars: new Conditions.ConditionVariables(new string[]
                                                                                                                                      { "Binding", a.assignedfunc }));
                                }
                            }
                        }

                        List <string> bindingstoexecute = new List <string>();

                        for (int i = 0; i < inonstate.Count; i++)
                        {
                            BindingsFile.Assignment a = inonstate[i];
                            if (a.KeyAssignementLongerThan(inonstate))  // we have the best key list
                            {
                                if (ispressable[i])
                                {
                                    assignmentsinonstate.Add(a);
                                }

                                bindingstoexecute.Add(a.assignedfunc);
                                System.Diagnostics.Debug.WriteLine("Action " + a.assignedfunc);
                            }
                            else
                            {
                                //System.Diagnostics.Debug.WriteLine("  Reject Rule due to others are longer " + inonstate[i].assignedfunc);
                            }
                        }

                        //System.Diagnostics.Debug.WriteLine("On state " + assignmentsinonstate.Count);

                        foreach (string s in bindingstoexecute)
                        {
                            ac.ActionRun("onEliteInput", "EliteUIEvent", additionalvars: new Conditions.ConditionVariables(new string[]
                                                                                                                           { "Device", je.Device.ID().Name, "Binding", s, "BindingList", String.Join(",", bindingstoexecute),
                                                                                                                             "EventName", match, "Pressed", je.Pressed?"1":"0", "Value", je.Value.ToStringInvariant() }));
                        }
                    }
                }
            }
        }