FileBrowserComponent and Keys

Hi guys,
I’m using a FileBrowserComponent to show and select some files. All working fine and I’m able to select either by clicking or by scrolling via keyboard. By user request, I’m trying to add a couple of scroll buttons (up and down) to my GUI, to change the currently selected file by going up or down the list.

I don’t know what am I doing wrong, but no matters if I try by overriding keyPressed or if I force the keystroke by sending it to the component, it’s just not working. I also tried to make a new derived class, from FileBrowserComponent, but nothing changes.

I had some checks and it looks like the up/down keys are used in the keyPressed method in the listBox used inside the FileBrowserComponent.

Any hints?

Thanks!

TL;DR:
overriding keyPressed if you are using a FileBrowserComponent won’t catch all keys. Up and Down keys are already used by the internal FileBrowserComponent listbox, so I haven’t found a way to detect those keys inside keyPressed callback in my custom component.

Any hint? I’m basically stuck.

Thanks

You may have a chance to catch it in a custom LookAndFeel, static_casting fileListComponent to FileListComponent* in layoutFileBrowserComponent() and calling setWantsKeyboardFocus(false) on it. Didn’t test it, not sure if it would work (or if it’s a good idea at all).

That was a solid hint and worked for me. In this way I’ve been able to block the default keyPress for the fileListComponent and, then, casting it in my keyPressed to send it the up/down keys along with my custom requirements. Thank you very much!

1 Like