 |
|
|
11-24-2020, 04:58 AM
|
#1
|
Human being with feelings
Join Date: Nov 2009
Posts: 146
|
"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!
|
|
|
11-24-2020, 10:23 AM
|
#2
|
Human being with feelings
Join Date: Apr 2016
Location: ASU`ogacihC
Posts: 2,250
|
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.
|
|
|
11-24-2020, 10:40 AM
|
#3
|
Human being with feelings
Join Date: Nov 2009
Posts: 146
|
Quote:
Originally Posted by Edgemeal
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 !!!
|
|
|
11-24-2020, 11:36 AM
|
#4
|
Human being with feelings
Join Date: Aug 2015
Posts: 226
|
Quote:
Originally Posted by Edgemeal
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.
|
|
|
11-24-2020, 12:48 PM
|
#5
|
Human being with feelings
Join Date: Apr 2016
Location: ASU`ogacihC
Posts: 2,250
|
Quote:
Originally Posted by shosty
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.
|
|
|
11-28-2020, 07:40 AM
|
#6
|
Human being with feelings
Join Date: Nov 2009
Posts: 146
|
Quote:
Originally Posted by Edgemeal
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
|
|
|
11-28-2020, 08:36 AM
|
#7
|
Human being with feelings
Join Date: Apr 2016
Location: ASU`ogacihC
Posts: 2,250
|
Quote:
Originally Posted by zabukowski
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.
|
|
|
Thread Tools |
|
Display Modes |
Linear Mode
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
All times are GMT -7. The time now is 07:11 AM.
|