# Component::keyPressed issue ( Duplicated event in Ableton, Event is not consumed even with "return true" in Studio One)

**URL:** <https://forum.juce.com/t/component-keypressed-issue-duplicated-event-in-ableton-event-is-not-consumed-even-with-return-true-in-studio-one/57874>\
**Category:** Development\
**Created:** [September 14, 2023, 3:04pm UTC](https://forum.juce.com/t/component-keypressed-issue-duplicated-event-in-ableton-event-is-not-consumed-even-with-return-true-in-studio-one/57874 "2023-09-14T15:04:54Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![hbjpn](https://avatars.discourse-cdn.com/v4/letter/h/8dc957/32.png) [@hbjpn](https://forum.juce.com/u/hbjpn)\
**Post date:** [September 14, 2023, 3:04pm UTC](https://forum.juce.com/t/component-keypressed-issue-duplicated-event-in-ableton-event-is-not-consumed-even-with-return-true-in-studio-one/57874/1 "2023-09-14T15:04:54Z")

</div>

I have the following issues regarding ‘keyPressed.’ Does anyone know the reason? Are these issues on the DAW side or the JUCE side?

Code:  
Following changes to the empty Plugin project generated by Projucer 7.0.7.

```auto
//==============================================================================
/**
*/
class NewProjectAudioProcessorEditor : public juce::AudioProcessorEditor
{
public:
    NewProjectAudioProcessorEditor (NewProjectAudioProcessor&);
    ~NewProjectAudioProcessorEditor() override;

    //==============================================================================
    void paint (juce::Graphics&) override;
    void resized() override;

    // --- Added from here
    virtual bool keyPressed(const juce::KeyPress& key) override {
        if (key.getKeyCode() == 65) {
            DBG("A received");
            return true;
        }
        return false;
    }
    // ----- to here

private:
    // This reference is provided as a quick way for your editor to
    // access the processor object that created it.
    NewProjectAudioProcessor& audioProcessor;

    JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (NewProjectAudioProcessorEditor)
};

```

Set setWantKeyboardFocus(true) in editor constructor.

```auto
NewProjectAudioProcessorEditor::NewProjectAudioProcessorEditor (NewProjectAudioProcessor& p)
    : AudioProcessorEditor (&p), audioProcessor (p)
{
    // Make sure that before the constructor has finished, you've set the
    // editor's size to whatever you need it to be.
    setWantsKeyboardFocus(true); // Added
    setSize (400, 300);
}

```

**Issue 1** Duplicated key press event in Ableton

- Environment : Windows 11 x64, Ableton Live 11.3.4
- Load vst3 plugin in DAW, in the plugin window press ‘a’ key once, then we receive 2 ‘a’ key events in the plugin

**Issue 2** Key press is not consumed with “return true” in Studio One

- Environment : Windows 11 x64, Studio One 6.1.1
- Load vst3 plugin in DAW, in the plugin window press ‘a’ key once, then we receive 1 ‘a’ key events in the plugin However, DAW also receive a key event and the function associated with key ‘a’ is triggered( by defualt Studio One swtich the automation view by key ‘a’)

---

<div class="post-metadata">

**Author:** ![HowardAntares](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/howardantares/32/4629_2.png) [@HowardAntares](https://forum.juce.com/u/HowardAntares)\
**Post date:** [September 14, 2023, 8:48pm UTC](https://forum.juce.com/t/component-keypressed-issue-duplicated-event-in-ableton-event-is-not-consumed-even-with-return-true-in-studio-one/57874/2 "2023-09-14T20:48:21Z")

</div>

Looking at a similar issue here. I think we have to use keyStateChanged() and detect the down and up changes to the keys we’re interested in. Haven’t made that change in my code to test with yet, though.

---

<div class="post-metadata">

**Author:** ![hbjpn](https://avatars.discourse-cdn.com/v4/letter/h/8dc957/32.png) [@hbjpn](https://forum.juce.com/u/hbjpn)\
**Post date:** [September 14, 2023, 11:38pm UTC](https://forum.juce.com/t/component-keypressed-issue-duplicated-event-in-ableton-event-is-not-consumed-even-with-return-true-in-studio-one/57874/3 "2023-09-14T23:38:14Z")

</div>

Thank you for infomration. I’ll try it.

---

<div class="post-metadata">

**Author:** ![reuk](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/reuk/32/21494_2.png) [@reuk](https://forum.juce.com/u/reuk)\
**Post date:** [October 11, 2023, 7:01pm UTC](https://forum.juce.com/t/component-keypressed-issue-duplicated-event-in-ableton-event-is-not-consumed-even-with-return-true-in-studio-one/57874/4 "2023-10-11T19:01:38Z")

</div>

We’ve made some changes to Windows plugin keyboard handling recently:

> <https://github.com/juce-framework/JUCE/commit/86d496d424f5587756b856acf17a3d1bb6456ece>
>
> This patch should resolve an issue introduced in
> 0ab30555fcf335fea220bc50cc8938e…c689a3800 where arrow keys and other
> directional keys (home, end, page up, page down) stopped working as
> expected.
> 
> With this patch in place,
> \- IME input in plugins should work correctly, including for languages
> with a selection palette (Japanese) and languages where multiple
> keypresses combine to a single character (Korean).
> \- Keyboard shortcuts should work (cut, copy, paste)
> \- Directional keys should work

Please try updating and check whether the issue is still present on the develop branch.

---

<div class="post-metadata">

**Author:** ![hbjpn](https://avatars.discourse-cdn.com/v4/letter/h/8dc957/32.png) [@hbjpn](https://forum.juce.com/u/hbjpn)\
**Post date:** [October 20, 2023, 11:44pm UTC](https://forum.juce.com/t/component-keypressed-issue-duplicated-event-in-ableton-event-is-not-consumed-even-with-return-true-in-studio-one/57874/5 "2023-10-20T23:44:07Z")

</div>

Hi reuk,

Thank you for the information.  
I confimred the issues are solved with that commit in develop branch. ( and confimred in released 7.0.8 as well).

Thank you !
