isKeyCurrentDown never return true

HI, i tried to wrote this code to prove me that KeyPress::isKeyCurrentlyDown never return true and effectively it doesn’t:

void timerCallback() override
    if (!KeyPress::isKeyCurrentlyDown(KeyPress::spaceKey)) 

My app has no a main window, it’s thought to show a little component near mouse position every time I press a key, but everywhere I put something like KeyPress::isKeyCurrentlyDown it’s never recognized that the key is pressed, even if I press it (I tried with a lot of keys to debug), initially I thought that it should be because I put it in a class that doesn’t inherit Component but even put it in a Component class (that is visible on screen) it doesn’t work.

I know that there are virtual methods in Component to listen whenever a key or a modifier is pressed, but for my app structure I can’t use them (actually I as I said I don’t have a component on screen for my app, is a background app).

Are you sure that you have focus?

I’m not 100% sure on your use case, but I don’t believe you’ll receive key events unless you have a component with some sort of focus on the keyboard.

I haven’t tested this but it’s just an intuitive guess because for a a lot of components (like the keyboard) if it does’t have focus it won’t receive key events.

Perhaps you want to somehow call wantsFocus(true) before these actions, however this is a component function, so I’m not sure how you’d acquire it without a component class. You may need to create some sort of invisible component.

In any case, I’m not sure JUCE is the correct framework to create a GUI less app which tracks users around their machine, this seems like something which would be very difficult to make cross platform

1 Like

Thank you! I’ll check!