Component::keyStateChanged(), bug?


#1

Component::keyStateChanged() doesn’t work with modifiers like Shift when they’re pressed. It does work when they’re released.

With other non-modifier keys, it works as expected.


#2

Component::modifierKeysChanged?


#3

That function works as expected. However, as I understand in the description:

keyStateChanged should work too with Modifiers standalone, in both press or release status, and currently it only works when they key is released. Did I misundestand the description?


#4

Hmm. Which OS?


#5

Windows XP Home (32bits), with lastest updates. I tested it debugging an empty VST created with IntroJucer in Reaper (debug mode)


#6

In a plugin, all bets are off because hosts can do silly things to the incoming events. But if you can show that it doesn’t work in an app then I’ll have a quick look.


#7

I’ve tested in this standalone project created with IntroJucer, debug mode, and I have the same problem. keyStateChanged() isn’t called when you press Ctrl key, only when it’s released:

TESTCOMP.H

[code]#ifndef XX
#define XX

#include “…/JuceLibraryCode/JuceHeader.h”

class TestComp: public DocumentWindow
{
public:
TestComp():
DocumentWindow(“a”, Colours::blue, true, true)
{
setWantsKeyboardFocus(true);
}

virtual bool keyStateChanged(bool isKeyDown)
{
DBG(String(isKeyDown));
return false;
}

};

#endif[/code]

MAIN.CPP

[code]/*

This file was auto-generated by the Introjucer!

It contains the basic startup code for a Juce application.

==============================================================================
*/

#include “…/JuceLibraryCode/JuceHeader.h”
#include “testcomp.h”

//==============================================================================
class NewProjectApplication : public JUCEApplication
{
public:
//==============================================================================
NewProjectApplication()
{

}

~NewProjectApplication()
{
}

//==============================================================================
void initialise (const String& commandLine)
{
    // Do your application's initialisation code here..
    testComp = new TestComp();
    testComp->setVisible(true);
    testComp->setBounds(100, 100, 400, 400);
    
}

void shutdown()
{
    // Do your application's shutdown code here..
    
}

//==============================================================================
void systemRequestedQuit()
{
    quit();
}

//==============================================================================
const String getApplicationName()
{
    return "NewProject";
}

const String getApplicationVersion()
{
    return ProjectInfo::versionString;
}

bool moreThanOneInstanceAllowed()
{
    return true;
}

void anotherInstanceStarted (const String& commandLine)
{
    
}

private:

ScopedPointer testComp;

};

//==============================================================================
// This macro generates the main() routine that starts the app.
START_JUCE_APPLICATION(NewProjectApplication)
[/code]


#8

Same problem here in a standalone on Linux (other OS not tested yet). I receive only a call on SHIFT-, CTRL- or ALT-release.


#9

yea here too (also on linux)


#10

Not sure what the problem exacly is, but it seems the currentModifiers is somethere updated incorrectly?

In juce_linux_Windowing.cpp, if handleModifierKeysChange is always called it seems to works correctly for modiefiers.
 


void handleKeyPressEvent (XKeyEvent& keyEvent) 
{ 
   ... 

   // if (oldMods != currentModifiers) 
      handleModifierKeysChange(); 

   ... 
}

#11

Can't test this right now, but to me it looks like the oldMods is just declared in the wrong place.. If you move that declaration up to the top of the function so that it gets stored before updateKeyModifiersFromSym is called, then does that do the job?


#12

Have made a copy of file from github. Works!

Thanks.