public override GameEvent UpdateEvent()
    {
        if (!base.UpdateEvent()) return null;

        KeyboardData k = new KeyboardData
        {
            key = InputKey
        };

        if (InputKey != KeyCode.None)
        {
            if (Input.GetKey(InputKey))
            {
                k.inputValue = 1.0f;
                k.inputType = Input.GetKeyDown(InputKey) ? InputType.PRESSED : InputType.HELD;

                Trigger(GameEventData.Empty.Add(new DataPiece(EventDataKeys.InputData) { data = k }));
            }
            else if (Input.GetKeyUp(InputKey))
            {
                k.inputValue = -1.0f;
                k.inputType = InputType.RELEASED;

                Trigger(GameEventData.Empty.Add(new DataPiece(EventDataKeys.InputData) { data = k }));
            }
        }

        return this;
    }
Esempio n. 2
0
 internal static void Initialize()
 {
     //Init devices
     Keyboard = new KeyboardData();
     Mouse = new MouseData();
     GamePads = new GamePadData[4];
     for (int i = 0; i < 4; i++)
         GamePads[i] = new GamePadData((PlayerIndex)i);
     VirtualInputs = new List<VirtualInput>();
 }
Esempio n. 3
0
            public void Should_Be_Greater_Than_Zero_If_Notified()
            {
                //Given
                KeyboardService sut    = new KeyboardServiceFixture();
                var             result = new KeyboardData();

                sut.KeyboardChanged.Subscribe(d => result = d);

                //When
                NSNotificationCenter.DefaultCenter.PostNotificationName(UIKeyboard.WillShowNotification, null);

                //Then
                result.Height.Should().BeGreaterThan(0);
            }
Esempio n. 4
0
            public void Should_Be_Faslse_If_Keyboard_Hides()
            {
                //Given
                KeyboardService sut    = new KeyboardServiceFixture();
                var             result = new KeyboardData();

                sut.KeyboardChanged.Subscribe((d => result = d));

                //When
                NSNotificationCenter.DefaultCenter.PostNotificationName(UIKeyboard.WillHideNotification, null);

                //Then
                result.IsVisible.Should().BeFalse();
            }
Esempio n. 5
0
        public async Task SendInput(KeyboardInput keyboardInput)
        {
            if (keyboardInput is null)
            {
                throw new ArgumentNullException(nameof(keyboardInput));
            }

            var request = new InputRequest
            {
                ElementId = Id
            };

            request.KeyboardData.AddRange(keyboardInput.Inputs.Select(i =>
            {
                var rv = new KeyboardData();
                switch (i)
                {
                case KeysInput keysInput:
                    rv.Keys.AddRange(keysInput.Keys.Cast <int>());
                    break;

                case TextInput textInput:
                    rv.TextInput = textInput.Text;
                    break;

                default:
                    throw new InvalidOperationException($"Unknown input type {i.GetType().FullName}");
                }
                return(rv);
            }));
            LogMessage?.Invoke($"{nameof(SendInput)}({keyboardInput})");
            if (await Client.SendInputAsync(request) is { } reply)
            {
                if (reply.LogMessages.Any() && LogMessage is { } logMessage)
                {
                    foreach (var message in reply.LogMessages)
                    {
                        logMessage(message);
                    }
                }
                if (reply.ErrorMessages.Any())
                {
                    throw new Exception(string.Join(Environment.NewLine, reply.ErrorMessages));
                }
                return;
            }

            throw new Exception("Failed to receive a reply");
        }
Esempio n. 6
0
        protected override void OnKeyPressed(KeyboardData key)
        {
            base.OnKeyPressed(key);

            if (key.KeyCode == TCODKeyCode.KeypadEight || key.KeyCode == TCODKeyCode.Up)
            {
                MovePosition(Direction.North);
            }

            if (key.KeyCode == TCODKeyCode.KeypadTwo || key.KeyCode == TCODKeyCode.Down)
            {
                MovePosition(Direction.South);
            }

            if (key.KeyCode == TCODKeyCode.KeypadFour || key.KeyCode == TCODKeyCode.Left)
            {
                MovePosition(Direction.West);
            }

            if (key.KeyCode == TCODKeyCode.KeypadSix || key.KeyCode == TCODKeyCode.Right)
            {
                MovePosition(Direction.East);
            }

            if (key.KeyCode == TCODKeyCode.KeypadSeven)
            {
                MovePosition(Direction.Northwest);
            }

            if (key.KeyCode == TCODKeyCode.KeypadNine)
            {
                MovePosition(Direction.Northeast);
            }

            if (key.KeyCode == TCODKeyCode.KeypadOne)
            {
                MovePosition(Direction.Southwest);
            }

            if (key.KeyCode == TCODKeyCode.KeypadThree)
            {
                MovePosition(Direction.Southeast);
            }

            if (key.KeyCode == TCODKeyCode.Escape)
            {
                ExitWindow();
            }
        }
        /// <summary>
        /// Add the new object to the queue for processing
        /// </summary>
        /// <param name="keyboardData">object with new data</param>
        /// <returns>number of outstanding requests</returns>
        public int AddToQueue(KeyboardData keyboardData)
        {
            //Make sure spot is available in the queue
            this.requestKeyboardData.WaitOne();

            lock (_threadLock)
            {
                dataQueue.Enqueue(keyboardData);
            }

            //Increament the semaphore to indicate there is job to do
            int previousCount = handleRequests.Release();

            return previousCount;
        }
    public override void Load(InstrumentData d)
    {
        KeyboardData data = d as KeyboardData;

        base.Load(data);

        output.ID     = data.jackOutID;
        freqoutput.ID = data.freqOutID;
        ampoutput.ID  = data.ampOutID;

        for (int i = 0; i < 3; i++)
        {
            _adsrInterface.xyHandles[i].setPercent(data.ADSRdata[i]);
        }
        _adsrInterface.setDefaults = false;

        muteButton.startToggled = data.muted;
        octaveToggle.setSwitch(data.octaveSwitch);

        if (data.midiInConnection != null & data.midiInConnection != "")
        {
            midiInButton.startToggled = true;
            _midiIn.ConnectByName(data.midiInConnection);
        }
        if (data.midiOutConnection != null & data.midiOutConnection != "")
        {
            midiOutButton.startToggled = true;
            _midiOut.ConnectByName(data.midiOutConnection);
        }

        sequenceButton.startToggled = data.sequencerEnabled;

        if (data.timelinePresent)
        {
            _timeline.SetTimelineData(data.timelineData);

            Vector3 pos = _timeline.heightHandle.transform.localPosition;
            pos.y = data.timelineHeight;
            _timeline.heightHandle.transform.localPosition = pos;
            _timeline.setStartHeight(data.timelineHeight);

            for (int i = 0; i < data.timelineEvents.Length; i++)
            {
                _timeline.SpawnTimelineEvent(data.timelineEvents[i].track, data.timelineEvents[i].in_out);
            }
        }
    }
Esempio n. 9
0
        private void ProcessKeyboard(KeyboardData data)
        {
            if (data.Query(GLFW_KEY_GRAVE_ACCENT, InputStates.PressedThisFrame))
            {
                IsVisible = !IsVisible;

                // TODO: Swap input control when the terminal is toggled.
                // When the terminal is active, it takes over input control.
                return;
            }

            if (!IsVisible)
            {
                return;
            }

            bool up   = data.Query(GLFW_KEY_UP, InputStates.PressedThisFrame);
            bool down = data.Query(GLFW_KEY_DOWN, InputStates.PressedThisFrame);

            if (up ^ down)
            {
                string text = null;

                if (up && storedIndex < oldCommands.Count - 1)
                {
                    storedIndex++;
                    text = oldCommands[oldCommands.Count - storedIndex - 1];
                }
                else if (down && storedIndex > -1)
                {
                    storedIndex--;
                    text = storedIndex >= 0 ? oldCommands[oldCommands.Count - storedIndex - 1] : "";
                }

                // If an old command is selected, other keys are ignored on the current frame.
                if (text != null)
                {
                    currentLine.Value   = text;
                    textProcessor.Value = text;

                    return;
                }
            }

            textProcessor.ProcessKeyboard(data);
            currentLine.Value = textProcessor.Value;
        }
Esempio n. 10
0
        private KeyboardData GetKeyboardData()
        {
            KeyboardData data = new KeyboardData((InputStates[])keys.Clone(), keyPresses.ToArray());

            for (int i = 0; i < keys.Length; i++)
            {
                switch (keys[i])
                {
                case InputStates.PressedThisFrame: keys[i] = InputStates.Held; break;

                case InputStates.ReleasedThisFrame: keys[i] = InputStates.Released; break;
                }
            }

            keyPresses.Clear();

            return(data);
        }
Esempio n. 11
0
        protected override void OnKeyPressed(KeyboardData keyData)
        {
            base.OnKeyPressed(keyData);

            if (Char.IsLetter(keyData.Character))
            {
                int index = Char.ToLower(keyData.Character) - 'a';
                if (index < _options.Count && index >= 0)
                {
                    _actionCount(_options[index]);
                    ExitWindow();
                }
            }
            else if (keyData.KeyCode == TCODKeyCode.Escape)
            {
                ExitWindow();
            }
        }
Esempio n. 12
0
        protected override void OnKeyPressed(KeyboardData key)
        {
            base.OnKeyPressed(key);

            if (_negative && _value > 0)
            {
                _value *= -1;
            }

            if (key.Character >= '0' && key.Character <= '9')
            {
                if (_firstUse)
                {
                    // if this is the first key press, any key press will replace the amount
                    _value    = 0;
                    _firstUse = false;
                }

                _value *= 10;

                _value += _negative ? -(key.Character - '0') : key.Character - '0';
            }
            else if (key.KeyCode == TCODKeyCode.Backspace)
            {
                _value /= 10;
            }
            else if (key.KeyCode == TCODKeyCode.KeypadSubtract || key.Character == '-')
            {
                _negative = !_negative;
                _value   *= -1;
            }
            _value = Math.Min(_maxValue, _value);
            _value = Math.Max(_minValue, _value);

            if (key.KeyCode == TCODKeyCode.Enter || key.KeyCode == TCODKeyCode.KeypadEnter)
            {
                _actionCount(_value);
                ExitWindow();
            }
            else if (key.KeyCode == TCODKeyCode.Escape)
            {
                ExitWindow();
            }
        }
Esempio n. 13
0
        private void ProcessKeyboard(KeyboardData data)
        {
            // Process frame advance.
            if (isFrameAdvanceEnabled && data.Query(GLFW_KEY_F, InputStates.PressedThisFrame))
            {
                isFrameAdvanceReady = true;
            }

            // Process reload.
            if (data.Query(GLFW_KEY_R, InputStates.PressedThisFrame))
            {
                // TODO: Clear the space visualizer.
                scene.Reload();
                jitterVisualizer.Clear();
            }

            bool controlHeld = data.Query(GLFW_KEY_LEFT_CONTROL, InputStates.Held) ||
                               data.Query(GLFW_KEY_RIGHT_CONTROL, InputStates.Held);

            if (!controlHeld)
            {
                return;
            }

            // Toggle frame advance mode.
            if (data.Query(GLFW_KEY_F, InputStates.PressedThisFrame))
            {
                isFrameAdvanceEnabled = !isFrameAdvanceEnabled;
            }

            // Toggle Jitter visualization.
            if (data.Query(GLFW_KEY_J, InputStates.PressedThisFrame))
            {
                jitterVisualizer.IsEnabled = !jitterVisualizer.IsEnabled;
            }

            // Toggle the scene's master renderer (meshes, skeletons, and 3D sprites).
            if (data.Query(GLFW_KEY_M, InputStates.PressedThisFrame))
            {
                var renderer = scene.Renderer;
                renderer.IsEnabled = !renderer.IsEnabled;
            }
        }
Esempio n. 14
0
        protected override void OnKeyPressed(KeyboardData keyData)
        {
            base.OnKeyPressed(keyData);

            if (keyData.Character == 'y')
            {
                _actionBoolean(true);
            }
            if (keyData.Character == 'n' || keyData.KeyCode == TCODKeyCode.Escape)
            {
                _actionBoolean(false);
            }
            if (keyData.KeyCode == TCODKeyCode.Space)
            {
                _actionBoolean(_defaultBooleanAction);
            }

            ExitWindow();
        }
Esempio n. 15
0
        private void ProcessKeyboard(KeyboardData data, float dt)
        {
            bool up    = data.Query(GLFW_KEY_W, InputStates.Held);
            bool down  = data.Query(GLFW_KEY_S, InputStates.Held);
            bool left  = data.Query(GLFW_KEY_A, InputStates.Held);
            bool right = data.Query(GLFW_KEY_D, InputStates.Held);

            vec2 accelerationDirection = vec2.Zero;

            if (left ^ right)
            {
                accelerationDirection.x = left ? -1 : 1;
            }

            if (up ^ down)
            {
                accelerationDirection.y = up ? -1 : 1;
            }

            if (accelerationDirection != vec2.Zero)
            {
                playerVelocity += accelerationDirection * Acceleration * dt;

                if (Utilities.LengthSquared(playerVelocity) > MaxSpeed * MaxSpeed)
                {
                    playerVelocity = Utilities.Normalize(playerVelocity) * MaxSpeed;
                }
            }
            else if (playerVelocity != vec2.Zero)
            {
                int previousSign = Math.Sign(playerVelocity.x != 0 ? playerVelocity.x : playerVelocity.y);

                playerVelocity -= Utilities.Normalize(playerVelocity) * Deceleration * dt;

                int newSign = Math.Sign(playerVelocity.x != 0 ? playerVelocity.x : playerVelocity.y);

                if (newSign != previousSign)
                {
                    playerVelocity = vec2.Zero;
                }
            }
        }
    public override InstrumentData GetData()
    {
        KeyboardData data = new KeyboardData();

        data.deviceType = menuItem.deviceType.Keyboard;
        GetTransformData(data);
        data.muted        = muted;
        data.octaveSwitch = octaveToggle.switchVal;
        data.ADSRdata     = new Vector2[3];
        for (int i = 0; i < 3; i++)
        {
            data.ADSRdata[i] = _adsrInterface.xyHandles[i].percent;
        }

        data.jackOutID = output.transform.GetInstanceID();
        data.freqOutID = freqoutput.transform.GetInstanceID();
        data.ampOutID  = ampoutput.transform.GetInstanceID();

        data.midiInConnection  = _midiIn.connectedDevice;
        data.midiOutConnection = _midiOut.connectedDevice;
        data.sequencerEnabled  = _timeline.gameObject.activeSelf;

        data.timelinePresent = true;
        data.timelineData    = _timeline.GetTimelineData();
        data.timelineHeight  = _timeline.heightHandle.transform.localPosition.y;
        List <timelineEvent.eventData> tempevents = new List <timelineEvent.eventData>();

        for (int i = 0; i < _timeline._tlEvents.Count; i++)
        {
            if (_timeline._tlEvents[i] != null)
            {
                tempevents.Add(_timeline._tlEvents[i].getEventInfo());
            }
        }
        data.timelineEvents = tempevents.ToArray();

        return(data);
    }
Esempio n. 17
0
        /// <summary>
        /// It should be noted that Managers always receive input messages, unlike controls.  A control
        /// needs to have the current keyboard focus before it can receive keyboard messages, for example.  All
        /// Manager objects added to the current Window will receive all mouse and keyboard messages.
        /// </summary>
        /// <param name="keyData"></param>
        protected override void OnKeyPressed(KeyboardData keyData)
        {
            base.OnKeyPressed(keyData);

            switch (keyData.KeyCode)
            {
            case libtcod.TCODKeyCode.Up:
                mapView.MovePlayer(0, -1);
                break;

            case libtcod.TCODKeyCode.Down:
                mapView.MovePlayer(0, 1);
                break;

            case libtcod.TCODKeyCode.Right:
                mapView.MovePlayer(1, 0);
                break;

            case libtcod.TCODKeyCode.Left:
                mapView.MovePlayer(-1, 0);
                break;
            }
        }
Esempio n. 18
0
        /// <summary>
        /// All ULA timing states are synchronized to this internal 7MHz clock.
        /// </summary>
        public void ExecuteOnPixelClock()
        {
            // Debug interface : breakpoints management
            ExitConditionException pendingExitException = null;

            // Video signals generation is aligned on a 16 pixels pattern
            int videoMem16StepsAccessPatternIndex = column % 16;

            // --- CPU/ULA video memory contention

            // The ULA accesses video memory from pixels 8 to 15
            // outside the border generation periods. To make sure
            // no CPU memory or IO access can overlap this period
            // we must stop any CPU memory or IO instruction starting
            // after pixel 4 and halt the CPU clock until next pixel 0.
            switch (videoMem16StepsAccessPatternIndex)
            {
            case 0:
                videoMemAccessTimeFrame = false;
                break;

            case 4:
                if (!generateBorder)
                {
                    videoMemAccessTimeFrame = true;
                }
                break;
            }

            if (videoMemAccessTimeFrame)
            {
                if (!haltCpuClock) // No need to check for CPU memory or IO requests while it is already halted
                {
                    if (           // CPU is about to access the video memory
                        // CPU is about to access the ULA IO port
                        cpuMemoryOrIORequestHalfTState == 1)
                    {
                        haltCpuClock = true;
                    }
                }
            }
            else
            {
                if (haltCpuClock)
                {
                    haltCpuClock = false;
                }
            }

            // --- CPU interrupt
            if (line == 248)
            {
                if (column == 0 /* Offset : because of the time necessary to read the first pixels in video memory, color output begins only 13 cycles after the master counter */ + 13)
                {
                    CpuINT = SignalState.LOW;
                }
                else if (column == 32 /* Offset : because of the time necessary to read the first pixels in video memory, color output begins only 13 cycles after the master counter */ + 13)
                {
                    CpuINT = SignalState.HIGH;
                }
            }

            // Connect TapeInput and SoundOutput
            if (TapeInputSignal.Level == 1)
            {
                SpeakerSoundSignal.Level = 1;
            }
            else if (!soundOutputWasSetByTheCPU)
            {
                SpeakerSoundSignal.Level = 0;
            }

            if (!haltCpuClock)
            {
                // --- CPU clock
                CpuCLK = PixelCLK; // C0 is directly used to drive CPU clock, but CPU T state starts with High state while ULA counter should start with C0 low

                // Check for CPU memory or IO access that could interfere with ULA operations
                if (cpuMemoryOrIORequestHalfTState == 0)
                {
                    // CPU is about to access the video memory
                    bool cpuMemoryOrIORequestToVideoAddress = (Address.SampleValue() & A15A14) == VideoMem;
                    // CPU is about to access the ULA IO port
                    cpuIORequestToULA = (CpuIORQ == SignalState.LOW) && ((Address.SampleValue() & A0) == (ULAPort & A0));
                    if (cpuIORequestToULA)
                    {
                        // Check to see if it is a read operation
                        cpuIORequestToULAIsREAD = CpuWR == SignalState.HIGH;
                    }
                    if (cpuMemoryOrIORequestToVideoAddress || cpuIORequestToULA)
                    {
                        cpuMemoryOrIORequestHalfTState = 1;
                    }
                }
                else if (cpuMemoryOrIORequestHalfTState > 0)
                {
                    cpuMemoryOrIORequestHalfTState++;
                }

                // --- CPU IO requests to ULA port
                if (cpuIORequestToULA)
                {
                    if (cpuIORequestToULAIsREAD)
                    {
                        if (cpuMemoryOrIORequestHalfTState == 5)
                        {
                            byte inputData = 0;
                            // Read keyboard state
                            KeyboardRD = SignalState.LOW;
                            inputData  = (byte)(KeyboardData.SampleValue() & ULAPort_Read_Keyboard);
                            KeyboardRD = SignalState.HIGH;
                            // Load cassette
                            inputData |= (byte)(TapeInputSignal.Level << ULAPort_Read_EAR);
                            // Bits 5 and 7 as read by INning from Port 0xfe are always one
                            inputData |= ULAPort_Read_Bits5And7;
                            Data.SetValue(inputData);
                        }
                        else if (cpuMemoryOrIORequestHalfTState == 6)
                        {
                            Data.ReleaseValue();
                        }
                    }
                    else
                    {
                        if (cpuMemoryOrIORequestHalfTState == 3)
                        {
                            byte writeData = Data.SampleValue();
                            // Write borderColor register
                            borderColorRegister = (byte)(writeData & ULAPort_Write_Border);
                            // Output sound
                            SpeakerSoundSignal.Level = (byte)((writeData & ULAPort_Write_Speaker) >> 4);
                            if (SpeakerSoundSignal.Level == 1)
                            {
                                soundOutputWasSetByTheCPU = true;
                            }
                            else
                            {
                                soundOutputWasSetByTheCPU = false;
                            }
                            // Save cassette
                            TapeOuputSignal.Level = (byte)(writeData & ULAPort_Write_MIC);
                        }
                    }
                }
                else if (cpuMemoryOrIORequestHalfTState == 3)
                {
                    // CPU is about to access the ULA IO port
                    cpuIORequestToULA = (CpuIORQ == SignalState.LOW) && ((Address.SampleValue() & A0) == (ULAPort & A0));
                    if (cpuIORequestToULA)
                    {
                        // Check to see if it is a read operation
                        cpuIORequestToULAIsREAD = CpuWR == SignalState.HIGH;
                    }
                    if (cpuIORequestToULA)
                    {
                        cpuMemoryOrIORequestHalfTState = 1;
                    }
                }
            }

            if (cpuMemoryOrIORequestHalfTState == 6)
            {
                cpuMemoryOrIORequestHalfTState = 0;
            }

            // --- Compute pixel colors ---
            if (displayPixels) // First thing to do at the falling edge of the clock
            {
                switch (videoMem16StepsAccessPatternIndex)
                {
                case 5:
                    displayRegister = displayLatch;
                    break;

                case 13:
                    displayRegister = displayLatch;
                    break;
                }
            }
            switch (videoMem16StepsAccessPatternIndex)
            {
            case 5:
                MultiplexAttributeLatchWithBorderColor();
                break;

            case 13:
                MultiplexAttributeLatchWithBorderColor();
                break;
            }

            // --- Load two display and attribute bytes for 16 pixels from video memory ---
            if (!generateBorder)
            {
                switch (videoMem16StepsAccessPatternIndex)
                {
                case 7:
                    ComputeVideoAddresses();
                    break;

                case 8:
                    // display address -> address bus
                    VideoAddress.SetValue(displayAddress);
                    VideoMREQ = SignalState.LOW;
                    VideoRD   = SignalState.LOW;
                    break;

                case 9:
                    displayLatch = VideoData.SampleValue();
                    VideoRD      = SignalState.HIGH;
                    VideoMREQ    = SignalState.HIGH;
                    VideoAddress.ReleaseValue();
                    break;

                case 10:
                    // attribute adress -> address bus
                    VideoAddress.SetValue(attributeAddress);
                    VideoMREQ = SignalState.LOW;
                    VideoRD   = SignalState.LOW;
                    break;

                case 11:
                    attributeLatch = VideoData.SampleValue();
                    VideoRD        = SignalState.HIGH;
                    VideoMREQ      = SignalState.HIGH;
                    VideoAddress.ReleaseValue();
                    ComputeVideoAddresses();
                    break;

                case 12:
                    // display colum address -> address bus
                    VideoAddress.SetValue(displayAddress);
                    VideoMREQ = SignalState.LOW;
                    VideoRD   = SignalState.LOW;
                    break;

                case 13:
                    displayLatch = VideoData.SampleValue();
                    VideoRD      = SignalState.HIGH;
                    VideoMREQ    = SignalState.HIGH;
                    VideoAddress.ReleaseValue();
                    break;

                case 14:
                    // attribute adress -> address bus
                    VideoAddress.SetValue(attributeAddress);
                    VideoMREQ = SignalState.LOW;
                    VideoRD   = SignalState.LOW;
                    break;

                case 15:
                    attributeLatch = VideoData.SampleValue();
                    VideoRD        = SignalState.HIGH;
                    VideoMREQ      = SignalState.HIGH;
                    VideoAddress.ReleaseValue();
                    break;
                }
            }

            // --- For each pixel : Video output signals ---

            // Generate horizontal and vertical synchronization signals
            if (column == 320 /* Offset : because of the time necessary to read the first pixels in video memory, color output begins only 13 cycles after the master counter */ + 13)
            {
                HSync = SignalState.LOW;
            }
            else if (column == 416 /* Offset : because of the time necessary to read the first pixels in video memory, color output begins only 13 cycles after the master counter */ + 13)
            {
                HSync = SignalState.HIGH;
                if (line == 247)
                {
                    VSync = SignalState.LOW;
                }
                else if (line == 255)
                {
                    VSync = SignalState.HIGH;
                }
            }

            // Compute pixel color for video output
            if (HSync == SignalState.LOW || VSync == SignalState.LOW)
            {
                // Blanking
                ColorSignal.Level = 0;
            }
            else
            {
                MultiplexDisplayRegisterWithAttributeRegisterAndFlashClock();
            }

            // Debug notification
            if (pendingExitException == null)
            {
                pendingExitException = NotifyLifecycleEvent(LifecycleEventType.ClockCycle);
            }

            // --- Increment master counters and prepare next iteration ---

            // Shift display register bits
            displayRegister = (byte)(displayRegister << 1);

            column++;
            if (column == 8)
            {
                if (!generateBorder)
                {
                    displayPixels = true;
                }
            }
            else if (column == 256)
            {
                generateBorder          = true;
                videoMemAccessTimeFrame = false;
            }
            else if (column == 264)
            {
                if (displayPixels)
                {
                    displayPixels = false;
                }
            }
            else if (column == 448)
            {
                column = 0;
                line++;

                // At each end of line send sound sample signal to the speaker
                // => 7 Mhz pixel clock / 448 pixels per line = 15.6 Khz sound sampling frequency
                SoundSampleCLK = SoundSampleCLK == SignalState.LOW ? SignalState.HIGH : SignalState.LOW;

                if (line < 192)
                {
                    generateBorder = false;
                }

                if (line == 312)
                {
                    line           = 0;
                    generateBorder = false;
                    frame++;

                    // Each 16 frames, invert flash clock
                    if (frame == 16)
                    {
                        frame      = 0;
                        flashClock = !flashClock;
                    }
                }
            }

            // Debug : if a breakpoint was hit, notify the pixel clock via a specific exception
            if (pendingExitException != null)
            {
                throw pendingExitException;
            }
        }
Esempio n. 19
0
        private IntPtr KeyboardProc(int nCode, IntPtr wParam, ref KeyboardData lParam)
        {
            if (nCode >= NativeConstants.HC_ACTION)
            {
                KeyboardEventArgs e;
                var vkCode = (Keys)lParam.vkCode;
                if ((int)wParam == NativeConstants.WM_KEYDOWN | (int)wParam == NativeConstants.WM_SYSKEYDOWN)
                {
                    if (vkCode == Keys.LMenu | vkCode == Keys.RMenu)
                    {
                        this.keyData = (this.keyData | Keys.Alt);
                        e            = new KeyboardEventArgs(this.keyData | Keys.Menu, vkCode);
                    }
                    else if (vkCode == Keys.LControlKey | vkCode == Keys.RControlKey)
                    {
                        this.keyData = (this.keyData | Keys.Control);
                        e            = new KeyboardEventArgs(this.keyData | Keys.ControlKey, vkCode);
                    }
                    else if (vkCode == Keys.LShiftKey | vkCode == Keys.RShiftKey)
                    {
                        this.keyData = (this.keyData | Keys.Shift);
                        e            = new KeyboardEventArgs(this.keyData | Keys.ShiftKey, vkCode);
                    }
                    else
                    {
                        e = new KeyboardEventArgs(this.keyData | vkCode, vkCode);
                    }

                    this.OnKeyDown(e);
                    if (e.Handled)
                    {
                        return(new IntPtr(1));
                    }
                }
                else if ((int)wParam == NativeConstants.WM_KEYUP | (int)wParam == NativeConstants.WM_SYSKEYUP)
                {
                    if (vkCode == Keys.LMenu | vkCode == Keys.RMenu)
                    {
                        this.keyData = (this.keyData & ~Keys.Alt);
                        e            = new KeyboardEventArgs(this.keyData | Keys.Menu, vkCode);
                    }
                    else if (vkCode == Keys.LControlKey | vkCode == Keys.RControlKey)
                    {
                        this.keyData = (this.keyData & ~Keys.Control);
                        e            = new KeyboardEventArgs(this.keyData | Keys.ControlKey, vkCode);
                    }
                    else if (vkCode == Keys.LShiftKey | vkCode == Keys.RShiftKey)
                    {
                        this.keyData = (this.keyData & ~Keys.Shift);
                        e            = new KeyboardEventArgs(this.keyData | Keys.ShiftKey, vkCode);
                    }
                    else
                    {
                        e = new KeyboardEventArgs(this.keyData | vkCode, vkCode);
                    }

                    this.OnKeyUp(e);
                    if (e.Handled)
                    {
                        return(new IntPtr(1));
                    }
                }
            }

            return(NativeExports.CallNextHookEx(this.handle, nCode, wParam, ref lParam));
        }
Esempio n. 20
0
 private void HandleKeyboardChanged(KeyboardData data)
 {
     //System.Diagnostics.Debug.WriteLine("IsVisible = " + data.IsVisible + " Height = " + data.Height);
     DisplayLabel.Text = "Visible = " + data.IsVisible + " Height = " + data.Height;
     //Do the cool stuff here
 }
Esempio n. 21
0
 public virtual void HandleKeyboard(KeyboardData data)
 {
 }
Esempio n. 22
0
 public static extern IntPtr CallNextHookEx(IntPtr idHook, int nCode, IntPtr wParam, ref KeyboardData lParam);
Esempio n. 23
0
 /// <summary>
 ///     Initializes the input system.
 /// </summary>
 internal static void Initialize()
 {
     Keyboard = new KeyboardData();
     Mouse    = new MouseData();
 }
Esempio n. 24
0
        private void ProcessKeyboard(KeyboardData data)
        {
            if (data.Query(GLFW_KEY_GRAVE_ACCENT, InputStates.PressedThisFrame))
            {
                IsDrawEnabled  = !IsDrawEnabled;
                isPauseToggled = true;

                return;
            }

            if (!IsDrawEnabled)
            {
                return;
            }

            // Tab completion takes priority over cycling through previous commands (assuming a new, valid match is
            // found).
            if (data.Query(GLFW_KEY_TAB, InputStates.PressedThisFrame))
            {
                ProcessAutocomplete();
            }

            // Cycle through old commands.
            bool up   = data.Query(GLFW_KEY_UP, InputStates.PressedThisFrame);
            bool down = data.Query(GLFW_KEY_DOWN, InputStates.PressedThisFrame);

            if (up ^ down)
            {
                string text = null;

                if (up && storedIndex < history.Count - 1)
                {
                    storedIndex++;
                    text = history[history.Count - storedIndex - 1];
                }
                else if (down && storedIndex > -1)
                {
                    storedIndex--;
                    text = storedIndex >= 0 ? history[history.Count - storedIndex - 1] : "";
                }

                // If an old command is selected, other keys are ignored on the current frame.
                if (text != null)
                {
                    currentLine.Value   = text;
                    textProcessor.Value = text;
                    autocomplete.Invalidate();

                    return;
                }
            }

            var oldValue  = textProcessor.Value;
            var oldCursor = textProcessor.Cursor;

            textProcessor.ProcessKeyboard(data);

            var newValue = textProcessor.Value;

            if (oldValue != newValue)
            {
                autocomplete.Invalidate();

                // Pressing space with a suggestion visible completes the suggestion (and adds a space).
                if (suggestionText.Length > 0 && newValue == oldValue + " ")
                {
                    var index = oldValue.LastIndexOf(' ');

                    currentLine.Value = (index == -1 ? suggestion : $"{oldValue.Substring(0, index)} {suggestion}")
                                        + " ";
                    textProcessor.Value  = currentLine.Value;
                    suggestionText.Value = null;

                    return;
                }

                currentLine.Value = newValue;

                if (oldCursor == oldValue.Length && newValue.Length > oldValue.Length)
                {
                    // Similar to Intellisense, suggestions are auto-filled while typing (but only while adding additional
                    // characters, not when backspacing or deleting).
                    if (!ProcessAutocomplete())
                    {
                        suggestionText.Value = null;
                    }
                }
                else
                {
                    suggestionText.Value = null;
                }
            }
        }
Esempio n. 25
0
 public void SessionChanged()
 {
     uniqueKeyCount = new short[FileHelper.GetEnumCount <KeysList>()];
     keystrokes.Clear();
     keyboardData = new KeyboardData();
 }
Esempio n. 26
0
        static void UpdateKeyboard(KeyboardData keyboard, IOHIDValueRef val)
        {
            IOHIDElementRef elem = NativeMethods.IOHIDValueGetElement(val);
            int v_int = NativeMethods.IOHIDValueGetIntegerValue(val).ToInt32();
            HIDPage page = NativeMethods.IOHIDElementGetUsagePage(elem);
            int usage = NativeMethods.IOHIDElementGetUsage(elem);
 
            // This will supress the debug printing below. Seems like it generates a lot of -1s. 
            // Couldn't find any details in USB spec or Apple docs for this behavior.
            if (usage >= 0)
            {

                switch (page)
                {
                    case HIDPage.GenericDesktop:
                    case HIDPage.KeyboardOrKeypad:
                        if (usage >= RawKeyMap.Length)
                        {
                            Debug.Print("[Warning] Key {0} not mapped.", usage);
                        }

                        keyboard.State[RawKeyMap[usage]] = v_int != 0;
                        break;
                }
            }
        }
        /// <summary>
        /// Processes the new keyboard data received from the queue
        /// </summary>
        /// <param name="inputData">new object with data</param>
        /// <returns>processing result</returns>
        private int ProcessKeyboardInput(KeyboardData inputData)
        {
            int keyboardResult = (int)ResultCodes.Success;

            do
            {
                if (inputData == null)
                {
                    keyboardResult = (int)ResultCodes.OutOfMemory;
                    keyboardLogger.Fatal("Error: The element removed from the Queue is NULL");
                    break;
                }

                if (inputData.KeyboardAction == (int)KeyboardAction.STOP)
                {
                    keyboardResult = HandleStopCommand();
                    break;
                }

                //if key is not pressed then do stuff or we'll calling release on pressed key
                if (!keysPressed.Exists(value => value.Equals(inputData.KeyboardAction)) || inputData.KeyPersistance == (int)KeyboardPersistance.RELEASE)
                {
                    keyboardLogger.Debug("Keyboard Command received = " + inputData.KeyboardAction);
                    UInt16 scanCode = GetKeyScanCode(inputData.KeyboardAction);
                    keyboardLogger.Debug("Keyboard scan code = " + scanCode);

                    if (scanCode == (UInt16)KeyBoardScanCodes.ScanCode.DIK_UNKNOWN)
                    {
                        keyboardResult = (int)ResultCodes.KeyboardCommandInvalid;
                        break;
                    }

                    keyboardLogger.Debug("Sending command to the game");

                    keyboardResult = SendKeyboardCommand(inputData.KeyPersistance, gameInfo.GetGameHandle(), scanCode, inputData.KeyboardAction);

                    keyboardLogger.Debug("Successfully sent the command to the game");
                }
                else
                {
                    keyboardLogger.Debug("The key is already pressed = " + inputData.KeyboardAction);
                }

            } while (false);

            return keyboardResult;
        }