示例#1
0
        public void ReceivingNativeInput_WhenHooked_CallsFactoryWithReceivedInput()
        {
            // Arrange
            Action <NativeKeyboardInput> nativeInputCallback = null;

            _nativeKeyboardHookServiceMock.Setup(f => f.Hook(It.IsAny <Action <NativeKeyboardInput> >())).Callback <Action <NativeKeyboardInput> >(a => nativeInputCallback = a);
            _keyboardInputFactoryMock.Setup(f => f.Create(It.IsAny <NativeKeyboardInput>()));

            var keyboardInput = new KeyboardInput(
                KeyboardInputKey.A,
                KeyboardInputDirection.KeyDown,
                new KeyboardInputLocks(false, false, false),
                new KeyboardInputModifiers(!false, false, false));

            _keyboardInputFactoryMock.Setup(f => f.Create(It.IsAny <NativeKeyboardInput>())).Returns(keyboardInput);

            var keyboardEventConfiguration = new KeyboardEventConfiguration(
                new KeyboardInputKeyConfiguration(KeyboardInputKey.AllKeys.ToArray()),
                ModifierConfiguration.CreateNotApplicable(),
                LockConfiguration.CreateNotApplicable());

            _receiverMock.Setup(f => f.ReceiveAsync(It.IsAny <KeyboardInput>())).Returns(Task.FromResult(true));
            _receiverMock.Setup(f => f.Configuration).Returns(keyboardEventConfiguration);
            _sut.HookKeyboard();

            var nativeKeyboardInput = new NativeKeyboardInput(Keys.A, NativeKeyboardInputDirection.KeyDown);

            // Act
            nativeInputCallback(nativeKeyboardInput);

            // Assert
            _keyboardInputFactoryMock.Verify(f => f.Create(nativeKeyboardInput), Times.Once);
        }
示例#2
0
 public static void InitialiseInputHandlers(System.Windows.Forms.Control mouseFocalControl)
 {
     KeyboardInputHandler = new NativeKeyboardInput();
     MouseInputHandler    = new MGForms_MouseInput(mouseFocalControl);
     //  System.Windows.Forms.Application.Idle += delegate { UpdateInputStates(); };
     inputHandlersReady = true;
 }
示例#3
0
        public void ReceivingNativeInput_ReceiverNotConfiguredForEvent_DoesNotCallReceiver()
        {
            // Arrange
            const bool ScrollLockMustBeActive = true;

            var keyboardInput = new KeyboardInput(
                KeyboardInputKey.A,
                KeyboardInputDirection.KeyDown,
                new KeyboardInputLocks(false, false, false),
                new KeyboardInputModifiers(!ScrollLockMustBeActive, false, false));

            var keyboardEventConfiguration = new KeyboardEventConfiguration(
                new KeyboardInputKeyConfiguration(KeyboardInputKey.AllKeys.ToArray()),
                ModifierConfiguration.CreateNotApplicable(),
                new LockConfiguration(ScrollLockMustBeActive, false, false));

            _receiverMock.Setup(f => f.ReceiveAsync(It.IsAny <KeyboardInput>())).Returns(Task.FromResult(true));
            _receiverMock.Setup(f => f.Configuration).Returns(keyboardEventConfiguration);

            _keyboardInputFactoryMock.Setup(f => f.Create(It.IsAny <NativeKeyboardInput>())).Returns(keyboardInput);

            Action <NativeKeyboardInput> nativeInputCallback = null;

            _nativeKeyboardHookServiceMock.Setup(f => f.Hook(It.IsAny <Action <NativeKeyboardInput> >())).Callback <Action <NativeKeyboardInput> >(a => nativeInputCallback = a);

            _sut.HookKeyboard();
            var nativeKeyboardInput = new NativeKeyboardInput(Keys.Alt, NativeKeyboardInputDirection.KeyUp);

            // Act
            nativeInputCallback(nativeKeyboardInput);

            // Assert
            _receiverMock.Verify(f => f.ReceiveAsync(It.IsAny <KeyboardInput>()), Times.Never);
        }
示例#4
0
        public void ReceivingNativeInput_ReceiverConfiguredForAllEvents_CallsReceiver()
        {
            // Arrange
            var keyboardEventConfiguration = KeyboardEventConfiguration.CreateForAllEvents();

            var keyboardInput = new KeyboardInput(
                KeyboardInputKey.A,
                KeyboardInputDirection.KeyDown,
                new KeyboardInputLocks(false, false, false),
                new KeyboardInputModifiers(true, false, false));

            _receiverMock.Setup(f => f.ReceiveAsync(It.IsAny <KeyboardInput>())).Returns(Task.FromResult(true));
            _receiverMock.Setup(f => f.Configuration).Returns(keyboardEventConfiguration);
            _keyboardInputFactoryMock.Setup(f => f.Create(It.IsAny <NativeKeyboardInput>())).Returns(keyboardInput);

            Action <NativeKeyboardInput> nativeInputCallback = null;

            _nativeKeyboardHookServiceMock.Setup(f => f.Hook(It.IsAny <Action <NativeKeyboardInput> >())).Callback <Action <NativeKeyboardInput> >(
                func =>
            {
                nativeInputCallback = func;
            });

            _sut.HookKeyboard();
            var nativeKeyboardInput = new NativeKeyboardInput(Keys.A, NativeKeyboardInputDirection.KeyDown);

            // Act
            nativeInputCallback(nativeKeyboardInput);

            // Assert
            _receiverMock.Verify(f => f.ReceiveAsync(It.IsAny <KeyboardInput>()), Times.Once);
        }
示例#5
0
 public KeyboardInput Create(NativeKeyboardInput nativeInput)
 {
     return(new KeyboardInput(
                _inputKeyMappingServant.MapFromNativeKey(nativeInput.Key),
                MapDirection(nativeInput.Direction),
                _lockOptionsFactory.Create(),
                _modiferOptionsFactory.Create()));
 }
示例#6
0
        private void OnNativeKeyboardInput(NativeKeyboardInput nativeKeyboardInput)
        {
            var keyboardInput = _inputFactory.Create(nativeKeyboardInput);

            var receivingTasks = _receivers
                                 .Where(receiver => receiver.Configuration.CheckIfApplicable(keyboardInput))
                                 .Select(receiver => receiver.ReceiveAsync(keyboardInput))
                                 .ToArray();

            Task.Run(() => Task.WhenAll(receivingTasks));
        }
示例#7
0
        public void Mapping_CallsModifierOptionsFactoryOnce()
        {
            // Arrange
            const Keys NativeKey           = Keys.A;
            var        nativeKeyboardInput = new NativeKeyboardInput(NativeKey, NativeKeyboardInputDirection.KeyDown);

            _inputKeyMappingServantMock.Setup(f => f.MapFromNativeKey(Keys.A)).Returns(KeyboardInputKey.A);
            _lockOptionsFactoryMock.Setup(f => f.Create()).Returns(new KeyboardInputLocks(true, true, true));
            _modifierOptionsFactoryMock.Setup(f => f.Create()).Returns(new KeyboardInputModifiers(true, true, true));

            // Act
            _sut.Create(nativeKeyboardInput);

            // Assert
            _modifierOptionsFactoryMock.Verify(f => f.Create(), Times.Once);
        }
示例#8
0
        public void Mapping_ReturnesMappedInput()
        {
            // Arrange
            const Keys NativeKey           = Keys.A;
            var        nativeKeyboardInput = new NativeKeyboardInput(NativeKey, NativeKeyboardInputDirection.KeyDown);

            _inputKeyMappingServantMock.Setup(f => f.MapFromNativeKey(Keys.A)).Returns(KeyboardInputKey.A);
            _lockOptionsFactoryMock.Setup(f => f.Create()).Returns(new KeyboardInputLocks(true, false, true));
            _modifierOptionsFactoryMock.Setup(f => f.Create()).Returns(new KeyboardInputModifiers(true, true, false));

            // Act
            var actualInput = _sut.Create(nativeKeyboardInput);

            // Assert
            Assert.AreEqual(KeyboardInputDirection.KeyDown, actualInput.Direction);
            Assert.AreEqual(KeyboardInputKey.A, actualInput.InputKey);
            Assert.AreEqual(true, actualInput.Locks.IsCapsLockActive);
            Assert.AreEqual(false, actualInput.Locks.IsNumLockActive);
            Assert.AreEqual(true, actualInput.Locks.IsScrollLockActive);
            Assert.AreEqual(true, actualInput.Modifiers.IsAltPressed);
            Assert.AreEqual(true, actualInput.Modifiers.IsCtrlPressed);
            Assert.AreEqual(false, actualInput.Modifiers.IsShiftPressed);
        }