Ejemplo n.º 1
0
        private static LogicalKey CreateKey(VirtualKeyCode keyCode, IInputSimulator inputSimulator, KeyBehaviour keyType, VirtualKeyCollection chordKeys, string outputText)
        {
            LogicalKey result = null;

            switch (keyType)
            {
            case KeyBehaviour.VirtualKey:
                result = CreateVirtualKey(keyCode, inputSimulator);
                break;

            case KeyBehaviour.Chord:
                result = CreateChordKey(keyCode, inputSimulator, chordKeys);
                break;

            case KeyBehaviour.Text:
                result = CreateTextKey(keyCode, inputSimulator, outputText);
                break;

            case KeyBehaviour.InstantaneousModifier:
                result = CreateInstantaneousModifierKey(keyCode, inputSimulator);
                break;

            case KeyBehaviour.TogglingModifier:
                result = CreateTogglingModifierKey(keyCode, inputSimulator);
                break;

            default:
                break;
            }

            return(result);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Initializes a new instance of the <see cref="MouseSimulator"/> class using an instance of a <see cref="WindowsInputMessageDispatcher"/> for dispatching <see cref="INPUT"/> messages.
        /// </summary>
        /// <param name="inputSimulator">The <see cref="IInputSimulator"/> that owns this instance.</param>
        public MouseSimulator(IInputSimulator inputSimulator)
        {
            if (inputSimulator == null) throw new ArgumentNullException("inputSimulator");

            _inputSimulator = inputSimulator;
            _messageDispatcher = new WindowsInputMessageDispatcher();
        }
        public ScreenKeyboardControlViewModel(Layout symbolBlock, List <Layout> languageBlocks, Layout numbersBlock,
                                              List <Layout> additionalBlocks, List <string> quickAccessPanelLayout, IInputSimulator inputSimulator)
        {
            _inputSimulator = inputSimulator;

            RegisterKeyInputCommand = new DelegateCommand(RegisterKeyInputExecute);
            ChangeTabCommand        = new DelegateCommand(ChangeTabExecute);

            TabsButtons    = new List <string>();
            LanguageBlocks = languageBlocks;
            InitKeyInputCommands(LanguageBlocks);

            CurrentLayout = LanguageBlocks[0];
            SymbolBlock   = symbolBlock;
            InitKeyInputCommands(new List <Layout>(1)
            {
                SymbolBlock
            });

            NumbersBlock = numbersBlock;
            InitKeyInputCommands(new List <Layout>(1)
            {
                NumbersBlock
            });

            IsLangMode = true;
        }
Ejemplo n.º 4
0
 /// <summary>
 /// Initializes a new instance of the <see cref="MouseSimulator"/> class using the specified <see cref="IInputMessageDispatcher"/> for dispatching <see cref="INPUT"/> messages.
 /// </summary>
 /// <param name="inputSimulator">The <see cref="IInputSimulator"/> that owns this instance.</param>
 /// <param name="messageDispatcher">The <see cref="IInputMessageDispatcher"/> to use for dispatching <see cref="INPUT"/> messages.</param>
 /// <exception cref="InvalidOperationException">If null is passed as the <paramref name="messageDispatcher"/>.</exception>
 internal MouseSimulator(IInputSimulator inputSimulator, IInputMessageDispatcher messageDispatcher)
 {
     _inputSimulator    = inputSimulator ?? throw new ArgumentNullException("inputSimulator");
     _messageDispatcher = messageDispatcher ?? throw new InvalidOperationException(
                                    string.Format("The {0} cannot operate with a null {1}. Please provide a valid {1} instance to use for dispatching {2} messages.",
                                                  typeof(MouseSimulator).Name, typeof(IInputMessageDispatcher).Name, typeof(INPUT).Name));
 }
Ejemplo n.º 5
0
 protected EmulatorDisplayInputControllerBase(IInputSimulator inputSimulator)
 {
     _inputSimulator = inputSimulator;
     PauseDurationAfterSendingKeyPress         = DefaultPauseDurationAfterAction;
     PauseDurationAfterSettingForegroundWindow = DefaultPauseDurationAfterAction;
     PauseDurationAfterPerformingGesture       = DefaultPauseDurationAfterAction;
     PauseDurationAfterTextEntry = DefaultPauseDurationAfterAction;
 }
Ejemplo n.º 6
0
        public AnalogKeyboardSimulator(IInputSimulator inputSimulator) : base(inputSimulator)
        {
            this.currentlyDownKeys    = new ConcurrentDictionary <VirtualKeyCode, BackgroundWorker>();
            this.currentlyDownAmounts = new ConcurrentDictionary <VirtualKeyCode, double>();
            this.pwmWorker            = new BackgroundWorker();

            PwmIntervalNanoseconds = 10000;
        }
Ejemplo n.º 7
0
 private static TextKey CreateTextKey(VirtualKeyCode keyCode, IInputSimulator inputSimulator, string outputText)
 {
     if (string.IsNullOrEmpty(outputText))
     {
         return(null);
     }
     return(new TextKey(inputSimulator, keyCode, outputText));
 }
 protected EmulatorDisplayInputControllerBase(IInputSimulator inputSimulator)
 {
     _inputSimulator = inputSimulator;
     PauseDurationAfterSendingKeyPress = DefaultPauseDurationAfterAction;
     PauseDurationAfterSettingForegroundWindow = DefaultPauseDurationAfterAction;
     PauseDurationAfterPerformingGesture = DefaultPauseDurationAfterAction;
     PauseDurationAfterTextEntry = DefaultPauseDurationAfterAction;
 }
Ejemplo n.º 9
0
 private static ChordKey CreateChordKey(VirtualKeyCode keyCode, IInputSimulator inputSimulator, VirtualKeyCollection chordKeys)
 {
     if (chordKeys == null || !chordKeys.Any())
     {
         return(null);
     }
     return(new ChordKey(inputSimulator, keyCode, chordKeys));
 }
Ejemplo n.º 10
0
 public ChordKey(IInputSimulator inputSimulator, VirtualKeyCode key, VirtualKeyCollection modifierKeys) : base(inputSimulator, key)
 {
     this.modifierKeys = new List <WindowsInput.Native.VirtualKeyCode>();
     foreach (VirtualKeyCode keyCode in modifierKeys)
     {
         this.modifierKeys.Add((WindowsInput.Native.VirtualKeyCode)keyCode);
     }
 }
Ejemplo n.º 11
0
 private static VirtualKey CreateVirtualKey(VirtualKeyCode keyCode, IInputSimulator inputSimulator)
 {
     if (keyCode == VirtualKeyCode.None)
     {
         return(null);
     }
     return(new VirtualKey(inputSimulator, keyCode));
 }
Ejemplo n.º 12
0
        public KeyboardSimulator(IInputSimulator inputSimulator) {
            if (inputSimulator == null) {
                throw new ArgumentNullException(nameof(inputSimulator));
            }

            _inputSimulator = inputSimulator;
            _messageDispatcher = new WindowsInputMessageDispatcher();
        }
Ejemplo n.º 13
0
        public void SendKeyboardAction(IInputSimulator simulator, VirtualKeyCode key)
        {
            if (simulator == null)
            {
                throw new ArgumentNullException();
            }

            simulator.Keyboard.KeyPress(key);
        }
Ejemplo n.º 14
0
 /// <summary>
 /// Initializes a new instance of the <see cref="KeyboardSimulator"/> class using the specified <see cref="IInputMessageDispatcher"/> for dispatching <see cref="INPUT"/> messages.
 /// </summary>
 /// <param name="inputSimulator">The <see cref="IInputSimulator"/> that owns this instance.</param>
 /// <param name="messageDispatcher">The <see cref="IInputMessageDispatcher"/> to use for dispatching <see cref="INPUT"/> messages.</param>
 /// <exception cref="InvalidOperationException">If null is passed as the <paramref name="messageDispatcher"/>.</exception>
 internal KeyboardSimulator(IInputSimulator inputSimulator, IInputMessageDispatcher messageDispatcher)
 {
     _inputSimulator    = inputSimulator ?? throw new ArgumentNullException(nameof(inputSimulator));
     _messageDispatcher = messageDispatcher ?? throw new InvalidOperationException(
                                    $"The {nameof(KeyboardSimulator)} cannot operate " +
                                    $"with a null {nameof(IInputMessageDispatcher)}. " +
                                    $"Please provide a valid {nameof(IInputMessageDispatcher)} instance " +
                                    $"to use for dispatching {nameof(INPUT)} messages.");
 }
Ejemplo n.º 15
0
        public KeyboardSimulator(IInputSimulator inputSimulator)
        {
            if (inputSimulator == null)
            {
                throw new ArgumentNullException(nameof(inputSimulator));
            }

            _inputSimulator    = inputSimulator;
            _messageDispatcher = new WindowsInputMessageDispatcher();
        }
Ejemplo n.º 16
0
        /// <summary>
        /// Initializes a new instance of the <see cref="MouseSimulator"/> class using an instance of a <see cref="WindowsInputMessageDispatcher"/> for dispatching <see cref="INPUT"/> messages.
        /// </summary>
        /// <param name="inputSimulator">The <see cref="IInputSimulator"/> that owns this instance.</param>
        public MouseSimulator(IInputSimulator inputSimulator)
        {
            if (inputSimulator == null)
            {
                throw new ArgumentNullException("inputSimulator");
            }

            _inputSimulator    = inputSimulator;
            _messageDispatcher = new WindowsInputMessageDispatcher();
        }
Ejemplo n.º 17
0
 internal KeyboardSimulator(IInputSimulator inputSimulator,
                            IInputMessageDispatcher messageDispatcher)
 {
     _inputSimulator    = inputSimulator ?? throw new ArgumentNullException(nameof(inputSimulator));
     _messageDispatcher = messageDispatcher ?? throw new InvalidOperationException(
                                    string.Format(
                                        "The {0} cannot operate with a null {1}. Please provide a valid {1} instance to use for dispatching {2} messages.",
                                        nameof(KeyboardSimulator), nameof(IInputMessageDispatcher),
                                        nameof(Win32Types.INPUT)));
 }
Ejemplo n.º 18
0
        /// <summary>
        /// Initializes a new instance of the <see cref="MouseSimulator"/> class using the specified <see cref="IInputMessageDispatcher"/> for dispatching <see cref="InputEntry"/> messages.
        /// </summary>
        /// <param name="inputSimulator">The <see cref="IInputSimulator"/> that owns this instance.</param>
        /// <param name="messageDispatcher">The <see cref="IInputMessageDispatcher"/> to use for dispatching <see cref="InputEntry"/> messages.</param>
        /// <exception cref="InvalidOperationException">If null is passed as the <paramref name="messageDispatcher"/>.</exception>
        internal MouseSimulator(IInputSimulator inputSimulator, IInputMessageDispatcher messageDispatcher) {
            if (inputSimulator == null) throw new ArgumentNullException(nameof(inputSimulator));

            if (messageDispatcher == null)
                throw new InvalidOperationException(
                        string.Format("The {0} cannot operate with a null {1}. Please provide a valid {1} instance to use for dispatching {2} messages.",
                                typeof(MouseSimulator).Name, typeof(IInputMessageDispatcher).Name, typeof(InputEntry).Name));

            _inputSimulator = inputSimulator;
            _messageDispatcher = messageDispatcher;
        }
Ejemplo n.º 19
0
 public TRexBrain()
 {
     Console.WriteLine("Press any key to boot up!");
     Console.ReadKey();
     Console.WriteLine("=== Brain has been booted ===");
     imageProcessor          = new TRexImageProcessor();
     inputSimulator          = new InputSimulator();
     TRex                    = new TRex(inputSimulator);
     increasePredictionTimer = new Timer(1000);
     Play();
 }
Ejemplo n.º 20
0
        /// <summary>
        /// Initializes a new instance of the <see cref="KeyboardSimulator"/> class using an instance of a <see cref="WindowsInputMessageDispatcher"/> for dispatching <see cref="INPUT"/> messages.
        /// </summary>
        /// <param name="inputSimulator">The <see cref="IInputSimulator"/> that owns this instance.</param>
        /// <param name="UseScanCodes">Tells the simulator to use ScanCodes instead of keycodes.</param>
        public KeyboardSimulator(IInputSimulator inputSimulator, bool useScanCodes = false)
        {
            if (inputSimulator == null)
            {
                throw new ArgumentNullException("inputSimulator");
            }

            _inputSimulator    = inputSimulator;
            _messageDispatcher = new WindowsInputMessageDispatcher();

            UseScanCodes = useScanCodes;
        }
 public InputListener(ISubject <ServerState> serverState, ILogger <InputListener> logger,
                      IInputSimulator inputSimulator, ApplicationSettings applicationSettings,
                      ICommandParser commandParser)
 {
     this.serverState = serverState;
     serverState.Subscribe(OnNext);
     this.logger              = logger;
     this.inputSimulator      = inputSimulator;
     this.applicationSettings = applicationSettings;
     this.commandParser       = commandParser;
     sessionList              = new List <Session>();
 }
Ejemplo n.º 22
0
        private int _corrY;            //correction for Y

        public InputService(IEventAggregator eventAggregator, IInputSimulator simulator)
        {
            _eventAggregator = eventAggregator;
            _simulator       = simulator;

            _rndX  = new Random();
            _rndY  = new Random();
            _corrX = 0;
            _corrY = 55;

            _eventAggregator.GetEvent <UpdateControlsEvent>().Subscribe(OnUpdateControls);
        }
Ejemplo n.º 23
0
        private static async Task RefreshPressEvery(IInputSimulator inputSimulator, TimeSpan delay, CancellationToken ct, TimeSpan?showMessageTime = null)
        {
            if (delay.TotalSeconds < 1)
            {
                throw new ArgumentException("The delay has to be at least one second long", nameof(delay));
            }

            // set delay for showing the messsage
            TimeSpan showMsgTime;

            if (showMessageTime.HasValue)
            {
                showMsgTime = showMessageTime.Value;
                if (delay.TotalSeconds <= showMsgTime.TotalSeconds)
                {
                    throw new ArgumentException("The show-message-time has to be shorter than the delay.", nameof(showMessageTime));
                }
            }
            else
            {
                TimeSpan fraction = delay.Divide(20);
                showMsgTime = fraction.TotalSeconds < MAX_SHOW_MESSAGE_DELAY ? fraction : TimeSpan.FromSeconds(MAX_SHOW_MESSAGE_DELAY);
            }

            delay = delay.Add(showMsgTime.Negate());

            while (!ct.IsCancellationRequested)
            {
                if (inputSimulator.InputDeviceState.IsKeyDown(VirtualKeyCode.RBUTTON))
                {
                    PrintOnCurrentLine("Right mouse button is already being held down. No action taken.");
                }
                else
                {
                    inputSimulator.Mouse.RightButtonDown();
                    PrintOnCurrentLine("Start holding down right mouse button.");
                }

                // show message for a bit
                try
                {
                    await Task.Delay(showMsgTime, ct);
                }
                catch (TaskCanceledException)
                {
                    return;
                }

                // count down to next refresh
                await CountDown("Next refresh in {0:hh\\:mm\\:ss}", delay, ct);
            }
        }
 public InputListenerV2(
     ISubject <ServerState> serverState,
     ILogger <InputListener> logger,
     IInputSimulator inputSimulator,
     ApplicationSettings applicationSettings,
     ICommandParser commandParser)
 {
     this.serverState         = serverState;
     this.logger              = logger;
     this.inputSimulator      = inputSimulator;
     this.applicationSettings = applicationSettings;
     this.commandParser       = commandParser;
 }
Ejemplo n.º 25
0
        /// <summary>
        /// Initializes a new instance of the <see cref="KeyboardSimulator"/> class using the specified <see cref="IInputMessageDispatcher"/> for dispatching <see cref="INPUT"/> messages.
        /// </summary>
        /// <param name="inputSimulator">The <see cref="IInputSimulator"/> that owns this instance.</param>
        /// <param name="messageDispatcher">The <see cref="IInputMessageDispatcher"/> to use for dispatching <see cref="INPUT"/> messages.</param>
        /// <exception cref="InvalidOperationException">If null is passed as the <paramref name="messageDispatcher"/>.</exception>
        internal KeyboardSimulator(IInputSimulator inputSimulator, IInputMessageDispatcher messageDispatcher)
        {
            if (inputSimulator == null)
            {
                throw new ArgumentNullException(nameof(inputSimulator));
            }

            if (messageDispatcher == null)
            {
                throw new InvalidOperationException(
                          string.Format("The {0} cannot operate with a null {1}. Please provide a valid {1} instance to use for dispatching {2} messages.",
                                        typeof(KeyboardSimulator).Name, typeof(IInputMessageDispatcher).Name, typeof(INPUT).Name));
            }

            _inputSimulator    = inputSimulator;
            _messageDispatcher = messageDispatcher;
        }
Ejemplo n.º 26
0
        public void SendKeyboardAction(IInputSimulator simulator, IEnumerable <VirtualKeyCode> modKeys, IEnumerable <VirtualKeyCode> signKeys)
        {
            if (simulator == null)
            {
                throw new ArgumentNullException();
            }

            if (modKeys.Any())
            {
                if (signKeys.Count() > 1 && signKeys.LastOrDefault() == VirtualKeyCode.LEFT)
                {
                    var offset = signKeys.Count() - 1;
                    var signKeysWithModKeys = signKeys.Take(offset);
                    simulator.Keyboard.ModifiedKeyStroke(modKeys, signKeysWithModKeys);
                    simulator.Keyboard.KeyPress(signKeys.Last());
                }
                else
                {
                    if (signKeys.Any())
                    {
                        simulator.Keyboard.ModifiedKeyStroke(modKeys, signKeys);
                    }
                    else
                    {
                        OnlyModKeyAction = true;
                    }
                }
            }
            else
            {
                var modKeysToPressOnce = Globals.GetModKeysToPressOnce().ToList();
                var modKeysToUse       = Globals.GetModKeysToHoldDown().ToList();
                modKeysToUse.AddRange(modKeysToPressOnce);
                if (modKeysToUse.Any())
                {
                    simulator.Keyboard.ModifiedKeyStroke(modKeysToUse, signKeys);
                }
                else
                {
                    simulator.Keyboard.KeyPress(signKeys.ToArray());
                }
            }
        }
Ejemplo n.º 27
0
        public CopypastaController(IClipboard clipboard, IClipboardHistoryManager clipboardHistoryManager,
                                   IClipboardBindingManager clipboardBindingManager, IHotkey ctrlVHotkey, IHotkey ctrlCHotkey, IHotkey escHotkey,
                                   IKeyTracker keyTracker, IInputSimulator inputSimulator, INotificationDispatcher notificationDispatcher)
        {
            _clipboard = clipboard;
            _clipboardHistoryManager = clipboardHistoryManager;
            _clipboardBindingManager = clipboardBindingManager;
            _ctrlVHotkey             = ctrlVHotkey;
            _ctrlCHotkey             = ctrlCHotkey;
            _escHotkey              = escHotkey;
            _keyTracker             = keyTracker;
            _inputSimulator         = inputSimulator;
            _notificationDispatcher = notificationDispatcher;
            _copypastaStateMachine  = new StateMachine <CopypastaState, CopypastaTrigger>(CopypastaState.Idle);
            _keyPressedTrigger      = _copypastaStateMachine.SetTriggerParameters <Key>(CopypastaTrigger.KeyPressed);

            ConfigureCopypastaStateMachine();
            ConfigureEventTriggers();
        }
Ejemplo n.º 28
0
        public override void EndInit()
        {
            inputSimulator = CreateInputSimulator();
            keys           = new Dictionary <UIElement, LogicalKey>();
            modifierKeys   = new List <ModifierKeyBase>();

            foreach (UIElement child in Children)
            {
                VirtualKeyCode       keyCode      = (VirtualKeyCode)child.GetValue(KeyCodeProperty);
                KeyBehaviour         keyBehaviour = (KeyBehaviour)child.GetValue(KeyBehaviourProperty);
                VirtualKeyCollection chordKeys    = (VirtualKeyCollection)child.GetValue(ChordKeysProperty);
                string outputText = (string)child.GetValue(OutputTextProperty);

                if (keyBehaviour == KeyBehaviour.None)
                {
                    // skip to the next child element
                    continue;
                }

                LogicalKey key = CreateKey(keyCode, inputSimulator, keyBehaviour, chordKeys, outputText);
                if (key == null)
                {
                    // skip to the next child element
                    continue;
                }

                ConnectToChildControl(child);
                keys.Add(child, key);
                key.KeyPressed += LogicalKeyPressed;

                if (keyBehaviour == KeyBehaviour.InstantaneousModifier || keyBehaviour == KeyBehaviour.TogglingModifier)
                {
                    modifierKeys.Add(key as ModifierKeyBase);
                }
            }

            SynchroniseModifierKeyState();
            base.EndInit();
        }
Ejemplo n.º 29
0
        public WiimoteInputControl()
        {
#if DUMMY_INPUT
            sim = new DummyInputSimulator();
#else
            sim = new InputSimulator();
#endif
            buttonInputs        = new IInputButton[(int)WiimoteButton.Count];
            overlayButtonInputs = new IInputButton[(int)WiimoteButton.Count];
            analogInputs        = new IInputAnalog[(int)WiimoteAnalog.Count];

            WiimoteManager.Connected         += OnWiimoteConnected;
            WiimoteManager.Discovered        += OnWiimoteDiscovered;
            WiimoteManager.AutoDiscoveryCount = 1;
            //FIXME: UnpairOnDisconnect is broken on Windows 10, it'll cause
            //       more problems than solve them at this point in time.
            WiimoteManager.UnpairOnDisconnect = false;        // true;
            WiimoteManager.PairOnDiscover     = false;        // true;
            //WiimoteManager.AutoConnect = false;
            //TODO: This control REALLY should not be messing with static settings. BAD!
            WiimoteManager.DolphinBarMode = true;
            WiimoteManager.BluetoothMode  = true;
            WiimoteManager.StartDiscovery();
        }
 protected WindowsEmulatorDisplayInputControllerBase(IInputSimulator inputSimulator)
     : base(inputSimulator)
 {
 }
Ejemplo n.º 31
0
 public TextKey(IInputSimulator inputSimulator, VirtualKeyCode key, string text) : base(inputSimulator, key)
 {
     Text = text;
 }
Ejemplo n.º 32
0
 public VirtualKey(IInputSimulator inputSimulator, VirtualKeyCode key)
     : base(inputSimulator, key)
 {
 }
Ejemplo n.º 33
0
 public void SendMouseAction(IInputSimulator simulator,
                             IEnumerable <VirtualKeyCode> modKeys,
                             IEnumerable <VirtualKeyCode> mouseKeys)
 {
     throw new System.NotImplementedException();
 }
Ejemplo n.º 34
0
 public Task SendKeyboardActionAsync(IInputSimulator simulator, IEnumerable <VirtualKeyCode> modKeys, IEnumerable <VirtualKeyCode> signKeys)
 {
     throw new System.NotImplementedException();
 }
 protected WindowsEmulatorDisplayInputControllerBase(IInputSimulator inputSimulator)
     : base(inputSimulator)
 {
 }