예제 #1
0
파일: Form1.cs 프로젝트: rgoliveira/ihc
        public Form1()
        {
            InitializeComponent();

            // setup fixed mappings (axis stuff)
            actions_always_run = new List <Action>();
            actions_always_run.Add(new Action("mouse", "Mouse Cursor")); // ls
            actions_always_run.Add(new Action("wheel", "Scrolling"));    // rs
            actions_always_run.Add(new Action("volume", "Volume"));      // triggers

            // read button mappings
            mappings = new List <ProgramMapping>();
            foreach (string filename in File.ReadLines(@"ini\mappings.cfg"))
            {
                if ((!filename.StartsWith(@"#")) && (File.Exists(filename)))
                {
                    mappings.Add(ProgramMapping.BuildFromFile(filename));
                }
            }

            // set current mapping
            current_mapping = mappings.Last();
            updateScreen();

            EventHook ehChanged = new EventHook(OnFocusChanged, EventHook.EVENT_SYSTEM_FOREGROUND);

            // start timer
            t           = new System.Timers.Timer(10);
            t.AutoReset = true;
            t.Elapsed  += OnTimedEvent;
            t.Enabled   = true;
        }
예제 #2
0
 static void SetMapping(string windowTitle)
 {
     Console.WriteLine(windowTitle);
     foreach (ProgramMapping pm in mappings)
     {
         Match m = Regex.Match(windowTitle, pm.program_regex_str, RegexOptions.IgnoreCase);
         if (m.Success)
         {
             current_mapping = pm;
             break;
         }
     }
 }
예제 #3
0
        public static ProgramMapping BuildFromFile(string filename)
        {
            var     parser = new FileIniDataParser();
            IniData data   = parser.ReadFile(filename);

            string name = data["ID"]["name"];
            string program_regex_str = data["PROGRAM"]["regex"];

            Dictionary <Types.ButtonFlags, Action> mappings = new Dictionary <Types.ButtonFlags, Action>();
            KeyDataCollection mapping_section = data["MAPPINGS"];
            KeyDataCollection labels_section  = data["LABELS"];

            if (mapping_section.ContainsKey("START"))
            {
                mappings.Add(Types.ButtonFlags.START, new Action(readMapping(mapping_section, "START"), labels_section["START"]));
            }
            if (mapping_section.ContainsKey("BACK"))
            {
                mappings.Add(Types.ButtonFlags.BACK, new Action(mapping_section["BACK"], labels_section["BACK"]));
            }
            if (mapping_section.ContainsKey("A"))
            {
                mappings.Add(Types.ButtonFlags.A, new Action(mapping_section["A"], labels_section["A"]));
            }
            if (mapping_section.ContainsKey("B"))
            {
                mappings.Add(Types.ButtonFlags.B, new Action(mapping_section["B"], labels_section["B"]));
            }
            if (mapping_section.ContainsKey("X"))
            {
                mappings.Add(Types.ButtonFlags.X, new Action(readMapping(mapping_section, "X"), labels_section["X"]));
            }
            if (mapping_section.ContainsKey("Y"))
            {
                mappings.Add(Types.ButtonFlags.Y, new Action(mapping_section["Y"], labels_section["Y"]));
            }
            if (mapping_section.ContainsKey("LEFT_SHOULDER"))
            {
                mappings.Add(Types.ButtonFlags.LEFT_SHOULDER, new Action(mapping_section["LEFT_SHOULDER"], labels_section["LEFT_SHOULDER"]));
            }
            if (mapping_section.ContainsKey("RIGHT_SHOULDER"))
            {
                mappings.Add(Types.ButtonFlags.RIGHT_SHOULDER, new Action(mapping_section["RIGHT_SHOULDER"], labels_section["RIGHT_SHOULDER"]));
            }
            if (mapping_section.ContainsKey("DPAD_DOWN"))
            {
                mappings.Add(Types.ButtonFlags.DPAD_DOWN, new Action(mapping_section["DPAD_DOWN"], labels_section["DPAD_DOWN"]));
            }
            if (mapping_section.ContainsKey("DPAD_LEFT"))
            {
                mappings.Add(Types.ButtonFlags.DPAD_LEFT, new Action(mapping_section["DPAD_LEFT"], labels_section["DPAD_LEFT"]));
            }
            if (mapping_section.ContainsKey("DPAD_UP"))
            {
                mappings.Add(Types.ButtonFlags.DPAD_UP, new Action(mapping_section["DPAD_UP"], labels_section["DPAD_UP"]));
            }
            if (mapping_section.ContainsKey("DPAD_RIGHT"))
            {
                mappings.Add(Types.ButtonFlags.DPAD_RIGHT, new Action(mapping_section["DPAD_RIGHT"], labels_section["DPAD_RIGHT"]));
            }

            return(ProgramMapping.Build(name, program_regex_str, mappings));
        }