Пример #1
0
        private void BuildMacroList()
        {
            //Build the Macro list
            MacroList.Items.Clear();
            //MacroList.Items.Add("NEW MACRO");

            // Add the files from the directory
            if (!System.IO.Directory.Exists(Globals.macroDir))
            {
                System.IO.Directory.CreateDirectory(Globals.macroDir);
            }

            String[] files = System.IO.Directory.GetFiles(Globals.macroDir, "*.mac");
            foreach (String name in files)
            {
                System.IO.FileStream        stream = new System.IO.FileStream(name, System.IO.FileMode.Open);
                MacroPlayer.MacroDefinition macro  = MacroPlayer.MacroDefinition.Read(stream);
                stream.Close();

                String[] pathComponents = name.Split('\\');
                pathComponents = pathComponents.Last().Split('.');
                macro.name     = pathComponents.First();

                MacroList.Items.Add(macro.name);
            }
        }
        public void RebuildFromMacroDefinition(MacroPlayer.MacroDefinition macro)
        {
            MacroCommands.Items.Clear();
            if (macro.sequence != null)
            {
                for (int i = 0; i < macro.sequence.Length; i++)
                {
                    MacroPlayer.KeySequenceEntry entry = macro.sequence[i];
                    ListViewItem item = new ListViewItem("" + entry.time);
                    if (entry.keyUp)
                    {
                        item.SubItems.Add("KeyUp");
                    }
                    else
                    {
                        switch (entry.keyType)
                        {
                        case 1:
                        {
                            item.SubItems.Add("KeyUp");
                            break;
                        }

                        case 2:
                        {
                            item.SubItems.Add("Mouse");
                            break;
                        }

                        default:
                        {
                            item.SubItems.Add("KeyDown");
                            break;
                        }
                        }
                    }
                    item.SubItems.Add("" + entry.keyCode);

                    MacroCommands.Items.Add(item);
                }
            }
            MacroName.Text        = macro.name;
            TimedMacro.Checked    = (macro.macroType & MacroPlayer.MacroDefinition.MacroType.kMacroMultiKey) == 0;
            MultikeyMacro.Checked = !TimedMacro.Checked;
            UseScanCodes.Checked  = (macro.macroType & MacroPlayer.MacroDefinition.MacroType.kMacroUseScanCodes) != 0;
        }
Пример #3
0
 void MapMacroKeys()
 {
     foreach (KeyMap DxKey in KeyMaps)
     {
         if (DxKey.Type == 0x3)
         {
             if (mMacros.ContainsKey(DxKey.MacroName))
             {
                 MacroPlayer.MacroDefinition macro = mMacros[DxKey.MacroName];
                 mKeyMacroSequenceMapping[DxKey.Dx1Key - 1] = macro;
             }
             else
             {
                 //Macro not found
                 DebugLog.Instance.writeLog("Error Macro listed wasn't found: " + DxKey.MacroName, true);
             }
         }
     }
 }
Пример #4
0
        private void EditMacros_Click(object sender, EventArgs e)
        {
            MacroPlayer.MacroDefinition macroEdited = null;

            int item = MacroList.SelectedIndex;

            if (item == -1)
            {
                return;
            }

            String name = MacroList.SelectedItem.ToString();

            if (item != 0)
            {
                macroEdited = mMacros[name];
            }
            else
            {
                macroEdited      = new MacroPlayer.MacroDefinition(null);
                macroEdited.name = GetUniqueMacroName();
            }
            MacroEditor edit = new MacroEditor();

            edit.RebuildFromMacroDefinition(macroEdited);
            if (edit.ShowDialog() == DialogResult.OK)
            {
                macroEdited = edit.GetMacroDefinition();
                if (macroEdited.name.Length > 0)
                {
                    System.IO.FileStream stream = new System.IO.FileStream(Globals.macroDir + macroEdited.name + ".mac", System.IO.FileMode.OpenOrCreate, System.IO.FileAccess.Write);
                    MacroPlayer.MacroDefinition.Write(stream, macroEdited);
                    stream.Close();
                }
            }
            RebuildMacroList();
        }
Пример #5
0
        private void EditMacros_Click(object sender, EventArgs e)
        {
            MacroPlayer.MacroDefinition macroEdited = null;

            int item = MacroList.SelectedIndex;
            if (item == -1)
                return;

            String name = MacroList.SelectedItem.ToString();
            if (item != 0)
                macroEdited = mMacros[name];
            else
            {
                macroEdited = new MacroPlayer.MacroDefinition(null);
                macroEdited.name = GetUniqueMacroName();
            }
            MacroEditor edit = new MacroEditor();
            edit.RebuildFromMacroDefinition(macroEdited);
            if (edit.ShowDialog() == DialogResult.OK)
            {
                macroEdited = edit.GetMacroDefinition();
                if (macroEdited.name.Length > 0)
                {
                    System.IO.FileStream stream = new System.IO.FileStream(Globals.macroDir + macroEdited.name + ".mac", System.IO.FileMode.OpenOrCreate, System.IO.FileAccess.Write);
                    MacroPlayer.MacroDefinition.Write(stream, macroEdited);
                    stream.Close();
                }

            }
            RebuildMacroList();
        }
Пример #6
0
        private void DoSomethingWithMacroKeys(byte[] data)
        {
            // need to sort the data by key number
            Array.Sort(data);
            Array.Reverse(data);

            int lastKeyIndex = 0;
            // for each of the possible keys
            int curIndex = 0;

            while (curIndex < kMacroPacketLength || lastKeyIndex < kMacroPacketLength)
            {
                byte last = (lastKeyIndex < kMacroPacketLength) ? mLastMacroKeyState[lastKeyIndex] : (byte)0;
                byte curr = (curIndex < kMacroPacketLength) ? data[curIndex] : (byte)0;

                // No more data
                if (last == 0 && curr == 0)
                {
                    break;
                }

                if (last == curr)       // No change
                {
                    lastKeyIndex++;
                    curIndex++;
                }
                else if (last > curr)       // Key Up
                {
                    lastKeyIndex++;

                    //Check to see if this is a Macro Key or a "Special Function"
                    if (KeyMaps[last - 1].Type > 3)
                    {
                        //New Special Key Function
                        SpecialKeyPlayer.KeyUp(KeyMaps[last - 1]);
                    }
                    else
                    {
                        //Standard Macro, use original Macro Player by Rob
                        MacroPlayer.MacroDefinition macroDef = mKeyMacroSequenceMapping[last - 1];
                        if (macroDef != null && (macroDef.macroType & MacroPlayer.MacroDefinition.MacroType.kMacroMultiKey) != 0)
                        {
                            macroDef.AllMacroKeysUp();
                        }
                    }
                }
                else                  // Key down
                {
                    //Check to see if this is a Macro Key or a "Special Function"
                    if (KeyMaps[curr - 1].Type > 3)
                    {
                        //New Special Key Function
                        SpecialKeyPlayer.KeyDown(KeyMaps[curr - 1]);
                    }
                    else
                    {
                        //Standard Macro, use original Macro Player by Rob

                        MacroPlayer.MacroDefinition macroDef = mKeyMacroSequenceMapping[curr - 1];
                        if (macroDef != null)
                        {
                            if ((macroDef.macroType & MacroPlayer.MacroDefinition.MacroType.kMacroMultiKey) == 0)
                            {
                                macroTimer.Stop();
                                System.DateTime time      = System.DateTime.Now;
                                TimeSpan        totalTime = time - initialTime;
                                UInt64          curTimeMS = (UInt64)totalTime.TotalMilliseconds;
                                // Create the new Macro instance

                                MacroPlayer.Macro macro           = new MacroPlayer.Macro(macroDef);
                                UInt64            timeToNextEvent = macro.InitMacroAtTime(curTimeMS);

                                // If the macro isn't instantaneous add it to the list.
                                if (timeToNextEvent != MacroPlayer.kForever)
                                {
                                    mMacroPlayer.Add(macro);
                                }

                                // process the rest of the running macros to this point.
                                UInt64 nextExistingMacroEventTime = mMacroPlayer.Tick(curTimeMS);

                                // And if any are still waiting start a timer
                                if (nextExistingMacroEventTime != MacroPlayer.kForever)
                                {
                                    macroTimer.AutoReset = false;
                                    macroTimer.Interval  = (UInt32)(nextExistingMacroEventTime - curTimeMS);
                                    macroTimer.Start();
                                }
                            }
                            else
                            {
                                macroDef.AllMacroKeysDown();
                            }
                        }
                    }


                    curIndex++;
                }
            }

            Array.Copy(data, mLastMacroKeyState, kMacroPacketLength);
        }