Old 01-04-2025, 08:52 AM   #1
JLP
Human being with feelings
 
Join Date: Jul 2019
Posts: 48
Default 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 !
JLP is offline   Reply With Quote
Old 01-04-2025, 12:55 PM   #2
cfillion
Human being with feelings
 
cfillion's Avatar
 
Join Date: May 2015
Location: Québec, Canada
Posts: 5,316
Default

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)
cfillion is offline   Reply With Quote
Old 01-05-2025, 12:01 AM   #3
JLP
Human being with feelings
 
Join Date: Jul 2019
Posts: 48
Default

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
JLP is offline   Reply With Quote
Old 01-05-2025, 04:01 PM   #4
cfillion
Human being with feelings
 
cfillion's Avatar
 
Join Date: May 2015
Location: Québec, Canada
Posts: 5,316
Default

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).
cfillion is offline   Reply With Quote
Old 01-08-2025, 10:28 AM   #5
JLP
Human being with feelings
 
Join Date: Jul 2019
Posts: 48
Default

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
JLP is offline   Reply With Quote
Old 01-22-2025, 12:45 PM   #6
JLP
Human being with feelings
 
Join Date: Jul 2019
Posts: 48
Default

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
I have an action that set the request_focus to "true", then from the main script, I've only be able to get the window focused using the JS API, because it seems to me that the window focusing function of ReaImGui relates to ReaImGui window (which seems to makes sense now that I'm writting it )

Any way, this piece of code work just fine !
JLP is offline   Reply With Quote
Old 01-22-2025, 01:28 PM   #7
Fergler
Human being with feelings
 
Fergler's Avatar
 
Join Date: Jan 2014
Posts: 5,320
Default

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?
Fergler is offline   Reply With Quote
Old 01-22-2025, 02:27 PM   #8
cfillion
Human being with feelings
 
cfillion's Avatar
 
Join Date: May 2015
Location: Québec, Canada
Posts: 5,316
Default

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.
cfillion is offline   Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -7. The time now is 09:55 PM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2025, vBulletin Solutions Inc.