01-04-2025, 08:52 AM | #1 |
Human being with feelings
Join Date: Jul 2019
Posts: 48
|
ReaImGui and shortcut focus
Hello everyone,
I'm working on simple script to show/hide track in MCP and TCP based on their name. For the GUI, I'm using ReaImGui, with a simple text box. Now, for it to be efficient in a real world situation, it would have to focus the text box with on a shortcut, no matter where the user is focused in the UI. I've tryied a couple of approches without any success so far. What would you recommand ? Thank you for your help ! |
01-04-2025, 12:55 PM | #2 |
Human being with feelings
Join Date: May 2015
Location: Québec, Canada
Posts: 5,316
|
Do you mean a shortcut key to focus the input field from within elsewhere in the window, like this?
Code:
package.path = reaper.ImGui_GetBuiltinPath() .. '/?.lua' local ImGui = require 'imgui' '0.9.3' local ctx = ImGui.CreateContext('My script') local function loop() local visible, open = ImGui.Begin(ctx, 'My window', true) if visible then if ImGui.Shortcut(ctx, ImGui.Mod_Ctrl | ImGui.Key_F, ImGui.InputFlags_RouteGlobal | ImGui.InputFlags_RouteOverActive) then ImGui.SetKeyboardFocusHere(ctx) end ImGui.InputText(ctx, 'My input') ImGui.End(ctx) end if open then reaper.defer(loop) end end reaper.defer(loop)
__________________
🎁 Donate (PayPal) | Sponsor (GitHub) | The Endless Journey (Keyboard Ensemble) ReaPack, a package manager for REAPER | SWS 2.14 is now available in ReaPack [new!] Developer tools: Lua profiler | Interactive ReaScript | ReaPack Editor | ReaImGui |
01-05-2025, 12:01 AM | #3 |
Human being with feelings
Join Date: Jul 2019
Posts: 48
|
Thank you very much, cfillion, for your answer !
You piece of code seems to work only if I'm focus in an ImGui window. If I'm focus in the arrange view for example, it does not work. I guess it's to be expected, but I was wondering how to build a mecanism to make it possible. Bellow is a link to a gif to try to show the "issue" better. https://drive.jeanlouppecquais.synol...aB-Nr5AOlrW8ws |
01-05-2025, 04:01 PM | #4 |
Human being with feelings
Join Date: May 2015
Location: Québec, Canada
Posts: 5,316
|
For a shortcut from REAPER you'll need a second script bound to a shortcut in the Action List.
Have it send some message to tell the first script it's time to call SetKeyboardFocusHere, for example using SetExtState (with persist=false).
__________________
🎁 Donate (PayPal) | Sponsor (GitHub) | The Endless Journey (Keyboard Ensemble) ReaPack, a package manager for REAPER | SWS 2.14 is now available in ReaPack [new!] Developer tools: Lua profiler | Interactive ReaScript | ReaPack Editor | ReaImGui |
01-08-2025, 10:28 AM | #5 |
Human being with feelings
Join Date: Jul 2019
Posts: 48
|
cfillon, thank you for your answer !
So it's kind of working. The textbox is effectively focused using another script and ExtState, but as the window hosting the script is not focused the keyboard is still redirected to the main window of REAPER. I'm digging in the API to found something |
01-22-2025, 12:45 PM | #6 |
Human being with feelings
Join Date: Jul 2019
Posts: 48
|
So just to share my solution on this problem, I've ended up doing this inside my main window function. :
Code:
if reaper.GetExtState("jlp_Track filter", "request_focus") == "true" then local window = reaper.JS_Window_Find('Track filter', true) reaper.JS_Window_SetFocus(window) ImGui.SetKeyboardFocusHere(ctx) end Any way, this piece of code work just fine ! |
01-22-2025, 01:28 PM | #7 |
Human being with feelings
Join Date: Jan 2014
Posts: 5,320
|
In my script, I have the opposite problem with focus, I don't want it at all. When I click in it I do not want to take focus from the main window. Does anyone know how to solve that?
|
01-22-2025, 02:27 PM | #8 |
Human being with feelings
Join Date: May 2015
Location: Québec, Canada
Posts: 5,316
|
WindowFlags_NoInputs to have clicks passthrough to the window behind. If you still want to process clicks then, instead of that, give focus back to the main window.
__________________
🎁 Donate (PayPal) | Sponsor (GitHub) | The Endless Journey (Keyboard Ensemble) ReaPack, a package manager for REAPER | SWS 2.14 is now available in ReaPack [new!] Developer tools: Lua profiler | Interactive ReaScript | ReaPack Editor | ReaImGui |
Thread Tools | |
Display Modes | |
|
|