Old 11-24-2020, 04:58 AM   #1
zabukowski
Human being with feelings
 
zabukowski's Avatar
 
Join Date: Nov 2009
Posts: 146
Default "Send key" action

Does anyone know, if it's possible to send key(s) from script to Reaper?

For example: i would like to open "Dynamic Split" dialog from custom action and then send "Enter"key to execute processing with default (last used) parameters.

Thx!
__________________
My software & music...
http://www.zabukowski.com/software
http://www.zabukowski.com
zabukowski is offline   Reply With Quote
Old 11-24-2020, 10:23 AM   #2
Edgemeal
Human being with feelings
 
Edgemeal's Avatar
 
Join Date: Apr 2016
Location: ASU`ogacihC
Posts: 2,250
Default

Normally you'd get the handle to the button and then send it a click message. One tricky part with the Dynamic split window is that the "Split" button is not enabled until after the dynamic split window has finished doing its work when opened, so we'd have to wait until the button is enabled or clicking it won't do anything. I didn't see an IsWindowEnabled function in the API so did it by checking the buttons style bits, only tested on Win10,..

NOTE: This Lua script requires the js_ReaScriptAPI extension!

Code:
local WS_DISABLED = 0x08000000 -- https://docs.microsoft.com/en-us/windows/win32/winmsg/window-styles

function ClickSplitButton()
  local parent = reaper.JS_Window_FindTop('Dynamic split items',true) 
  if parent then
    local btn = reaper.JS_Window_FindChildByID(parent, 0x1) -- get handle to "Split" button
    if btn then -- check if button is enabled
      local style = reaper.JS_Window_GetLong(btn, "STYLE")
      if style & WS_DISABLED == WS_DISABLED then
        reaper.defer(ClickSplitButton) -- loop & try again.
      else -- send btn a left mouse click msg
        reaper.JS_WindowMessage_Send(btn, "WM_LBUTTONDOWN", 1, 0, 0, 0)
        reaper.JS_WindowMessage_Send(btn, "WM_LBUTTONUP", 0, 0, 0, 0) 
      end 
    end
  end
end

-- open dynamic split items window
reaper.Main_OnCommand(40760, 0) -- Item: Dynamic split items...
-- click the "Split" button.
ClickSplitButton()

Last edited by Edgemeal; 11-24-2020 at 10:37 AM.
Edgemeal is offline   Reply With Quote
Old 11-24-2020, 10:40 AM   #3
zabukowski
Human being with feelings
 
zabukowski's Avatar
 
Join Date: Nov 2009
Posts: 146
Default

Quote:
Originally Posted by Edgemeal View Post
Normally you'd get the handle to the button and then send it a click message. One tricky part with the Dynamic split window is that the "Split" button is not enabled until after the dynamic split window has finished doing its work when opened, so we'd have to wait until the button is enabled or clicking it won't do anything. I didn't see an IsWindowEnabled function in the API so did it by checking the buttons style bits, only tested on Win10,..

NOTE: This Lua script requires the js_ReaScriptAPI extension!

Code:
local WS_DISABLED = 0x08000000 -- https://docs.microsoft.com/en-us/windows/win32/winmsg/window-styles

function ClickSplitButton()
  local parent = reaper.JS_Window_FindTop('Dynamic split items',true) 
  if parent then
    local btn = reaper.JS_Window_FindChildByID(parent, 0x1) -- get handle to "Split" button
    if btn then -- check if button is enabled
      local style = reaper.JS_Window_GetLong(btn, "STYLE")
      if style & WS_DISABLED == WS_DISABLED then
        reaper.defer(ClickSplitButton) -- loop & try again.
      else -- send btn a left mouse click msg
        reaper.JS_WindowMessage_Send(btn, "WM_LBUTTONDOWN", 1, 0, 0, 0)
        reaper.JS_WindowMessage_Send(btn, "WM_LBUTTONUP", 0, 0, 0, 0) 
      end 
    end
  end
end

-- open dynamic split items window
reaper.Main_OnCommand(40760, 0) -- Item: Dynamic split items...
-- click the "Split" button.
ClickSplitButton()
Woooow, perfect, big thanks for this !!!
__________________
My software & music...
http://www.zabukowski.com/software
http://www.zabukowski.com
zabukowski is offline   Reply With Quote
Old 11-24-2020, 11:36 AM   #4
shosty
Human being with feelings
 
Join Date: Aug 2015
Posts: 226
Default

Quote:
Originally Posted by Edgemeal View Post
Normally you'd get the handle to the button and then send it a click message.
How do you find this? I've had a similar problem with the midi learn last touched parameter, I would like to assign it to a button so I can press it, midi learn and the dialog closes but I can't find a way to press OK/enter as an action.
shosty is offline   Reply With Quote
Old 11-24-2020, 12:48 PM   #5
Edgemeal
Human being with feelings
 
Edgemeal's Avatar
 
Join Date: Apr 2016
Location: ASU`ogacihC
Posts: 2,250
Default

Quote:
Originally Posted by shosty View Post
How do you find this? I've had a similar problem with the midi learn last touched parameter, I would like to assign it to a button so I can press it, midi learn and the dialog closes but I can't find a way to press OK/enter as an action.
If you know for sure there is only one child window on the parent window with exact text, lets say its "OK", or "ok" (case doesn't matter) then you can safely use JS_Window_FindChild() to get its handle, for example,..
Code:
btn = reaper.JS_Window_FindChild(parent, "OK", true)
Note that some dialogs can block scripts from running, if you need more help post image(s) of the exact window(s) you're referring to.
Edgemeal is offline   Reply With Quote
Old 11-28-2020, 07:40 AM   #6
zabukowski
Human being with feelings
 
zabukowski's Avatar
 
Join Date: Nov 2009
Posts: 146
Default

Quote:
Originally Posted by Edgemeal View Post
Normally you'd get the handle to the button and then send it a click message. One tricky part with the Dynamic split window is that the "Split" button is not enabled until after the dynamic split window has finished doing its work when opened, so we'd have to wait until the button is enabled or clicking it won't do anything. I didn't see an IsWindowEnabled function in the API so did it by checking the buttons style bits, only tested on Win10,..

NOTE: This Lua script requires the js_ReaScriptAPI extension!
Where can i find more detailed documentation for js_ReaScriptAPI extension?

Unfortunately, your script doesn't work on macOS
__________________
My software & music...
http://www.zabukowski.com/software
http://www.zabukowski.com
zabukowski is offline   Reply With Quote
Old 11-28-2020, 08:36 AM   #7
Edgemeal
Human being with feelings
 
Edgemeal's Avatar
 
Join Date: Apr 2016
Location: ASU`ogacihC
Posts: 2,250
Default

Quote:
Originally Posted by zabukowski View Post
Where can i find more detailed documentation for js_ReaScriptAPI extension?

Unfortunately, your script doesn't work on macOS
That sucks, don't have a MAC here, Ask in the JS_API thread, hopefully someone there with a MAC can help.
Edgemeal 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 07:11 AM.


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