Ejemplo n.º 1
0
        private async Task PlayMacroOnce(int offset, ObservableCollection <ButtonAction> actions)
        {
            MacroStarted?.Invoke(this, new MacroStartedEventArgs(offset, (int)Win32Structures.ScanCodeShort.MACRO_STARTED));

            foreach (var action in actions)
            {
                if (_activeMacros.ContainsKey(offset) == false)
                {
                    break;
                }

                if (action.TimeInMilliseconds > 0)
                {
                    //yes this is precise only to the nearest KeyDownRepeatDelay milliseconds. repeated keys are on a 60 millisecond boundary, so the UI could be locked to 60ms increments only
                    var timeLeft = action.TimeInMilliseconds;
                    while (timeLeft > 0)
                    {
                        await Task.Delay(Keyboard.KeyDownRepeatDelay);

                        if (!_activeMacros.ContainsKey(offset))
                        {
                            return;
                        }
                        timeLeft -= Keyboard.KeyDownRepeatDelay;
                    }
                }

                Keyboard.SendKeyPress(action.ScanCode, action.IsKeyUp, action.IsExtended);

                if (action.IsKeyUp)
                {
                    KeystrokeUpSent?.Invoke(this, new KeystrokeSentEventArgs(offset, offset, action.ScanCode, action.IsKeyUp, action.IsExtended));
                }
                else
                {
                    KeystrokeDownSent?.Invoke(this, new KeystrokeSentEventArgs(offset, offset, action.ScanCode, action.IsKeyUp, action.IsExtended));
                }
            }
            _activeMacros.TryRemove(offset, out _);
        }
Ejemplo n.º 2
0
 private void Device_MacroStarted(object sender, MacroStartedEventArgs e)
 {
     MacroStarted?.Invoke(sender, e);
 }