public UInt64 ProcessMacroToTime(UInt64 time)
            {
                List <INPUT> keyCommands = new List <INPUT>();

                for (; IP < macroKeys.sequence.Length; IP++)
                {
                    KeySequenceEntry entry = macroKeys.sequence[IP];
                    if (baseTime + entry.time > time)
                    {
                        break;
                    }

                    INPUT temp = new INPUT();
                    if (entry.keyType != 2)
                    {
                        //Standard keyboard playback
                        temp.type = INPUT_KEYBOARD;
                        if (((macroKeys.macroType & MacroDefinition.MacroType.kMacroUseScanCodes) != 0))
                        {
                            temp.ki.wScan   = (ushort)entry.keyCode;
                            temp.ki.dwFlags = KEYEVENTF_SCANCODE | (entry.keyUp ? KEYEVENTF_KEYUP : 0);
                        }
                        else
                        {
                            temp.ki.wVk     = entry.keyCode;
                            temp.ki.dwFlags = entry.keyUp ? KEYEVENTF_KEYUP : 0;
                        }
                    }
                    else
                    {
                        //New Mouse playback
                        temp.type         = INPUT_MOUSE;
                        temp.mi.dx        = 0;
                        temp.mi.dy        = 0;
                        temp.mi.mouseData = 0;
                        temp.mi.dwFlags   = (uint)entry.keyCode;
                    }
                    keyCommands.Add(temp);
                }
                INPUT[] keyArray = keyCommands.ToArray();
                if (keyArray.Length > 0)
                {
                    int size = Marshal.SizeOf(keyArray[0]);
                    SendInput((uint)keyArray.Length, keyArray, size);
                }

                return(IP < macroKeys.sequence.Length ? macroKeys.sequence[IP].time + baseTime : kForever);
            }
            // Invert order for Key up
            private List <INPUT> CreateKeyUpInputList()
            {
                List <INPUT> keyActions = new List <INPUT>();

                for (int i = sequence.Length - 1; i >= 0; --i)
                {
                    KeySequenceEntry entry = sequence[i];
                    INPUT            temp  = new INPUT();
                    temp.type = INPUT_KEYBOARD;
                    if ((macroType & MacroDefinition.MacroType.kMacroUseScanCodes) != 0)
                    {
                        // Note scan codes send a different value for key up
                        temp.ki.wScan   = (ushort)entry.keyCode;
                        temp.ki.dwFlags = KEYEVENTF_SCANCODE | KEYEVENTF_KEYUP;
                    }
                    else
                    {
                        temp.ki.wVk     = entry.keyCode;
                        temp.ki.dwFlags = KEYEVENTF_KEYUP;
                    }
                    keyActions.Add(temp);
                }
                return(keyActions);
            }
            private List <INPUT> CreateKeyDownInputList()
            {
                List <INPUT> keyActions = new List <INPUT>();

                for (int i = 0; i < sequence.Length; i++)
                {
                    KeySequenceEntry entry = sequence[i];
                    INPUT            temp  = new INPUT();
                    temp.type = INPUT_KEYBOARD;
                    if ((macroType & MacroDefinition.MacroType.kMacroUseScanCodes) != 0)
                    {
                        temp.ki.wScan   = entry.keyCode;
                        temp.ki.dwFlags = KEYEVENTF_SCANCODE;
                    }
                    else
                    {
                        temp.ki.wVk     = entry.keyCode;
                        temp.ki.dwFlags = 0;
                    }

                    keyActions.Add(temp);
                }
                return(keyActions);
            }
 public MacroDefinition(KeySequenceEntry[] keys)
 {
     sequence = keys;
 }
 public MacroDefinition(String n, KeySequenceEntry[] keys, MacroType type)
 {
     name = n;
     sequence = keys;
     macroType = type;
 }