示例#1
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);
        }
        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);
        }