Go Back   Cockos Incorporated Forums > REAPER Forums > ReaScript, JSFX, REAPER Plug-in Extensions, Developer Forum

Reply
 
Thread Tools Display Modes
Old 01-24-2019, 08:01 AM   #1
TonE
Human being with feelings
 
Join Date: Feb 2009
Location: Reaper HAS send control via midi !!!
Posts: 4,031
Default Triggering custom actions using AutoHotkey with Postmessage?

Does anyone know how to trigger custom actions in Reaper from AutoHotkey using Postmessage?

For normal actions it is easy, you can use:
PHP Code:
ReaperLove(ID)
{
    global
    
Postmessage,0x111,ID,,,ahk_class REAPERwnd
    
return

TonE is offline   Reply With Quote
Old 01-24-2019, 08:45 AM   #2
Edgemeal
Human being with feelings
 
Edgemeal's Avatar
 
Join Date: Apr 2016
Location: ASU`ogacihC
Posts: 3,913
Default

You can't, you'd have to write a script in reaper to convert them first then save to say a file that your AHK script could read. For the fun of it I slapped this together real quick just to see if it was possible...

https://forum.cockos.com/showpost.ph...2&postcount=22
Edgemeal is offline   Reply With Quote
Old 01-24-2019, 09:32 AM   #3
TonE
Human being with feelings
 
Join Date: Feb 2009
Location: Reaper HAS send control via midi !!!
Posts: 4,031
Default

Thanks for replying, but this is for sure not something I would use. My goal is always making things simpler, not the opposite. For now I am just triggering the Reaper hotkey bindings.

This is what I am using right now, in AutoHotkey. Hitting Alt-Enter toggles between hackey trackey and hackey patterns, you could use any hotkey you like. As I could not achieve this by internal methods, for now I am using this solution. I guess even lua or python should be able to close windows based on the window title. Then a .lua or .py action could replace this.

This is all not ideal now, but better than nothing.
PHP Code:
!Enter::
IfWinExistHackey Trackey
{
  
WinCloseHackey Trackey 
  
start patterns here
  
Notify("start patterns here")
  
Send ^requirementCtrl+1 is mapped in Reaper to Hackey Patterns
}

IfWinExistHackey Patterns
{
  
WinCloseHackey Patterns
  
start tracker here
  
Notify("start tracker here")
  
Send ^requirementCtrl+2 is mapped in Reaper to Hackey Trackey or tracker.lua
}
return 
TonE is offline   Reply With Quote
Old 01-24-2019, 09:46 AM   #4
Edgemeal
Human being with feelings
 
Edgemeal's Avatar
 
Join Date: Apr 2016
Location: ASU`ogacihC
Posts: 3,913
Default

You could probably write that in a lua script using js_ReaScriptAPI extension, I don't understand AHK, but commands are probably pretty similar,.. something like

Code:
hwnd = reaper.JS_Window_Find("Hackey Trackey", true)-- find window by title bar text
if hwnd then -- close the window
  reaper.JS_WindowMessage_Post(hwnd, "WM_CLOSE", 0,0,0,0)
else -- do something else like launch a script,.. 
 reaper.Main_OnCommand(cmd_id, 0)
end
Edgemeal is offline   Reply With Quote
Old 01-24-2019, 01:48 PM   #5
TonE
Human being with feelings
 
Join Date: Feb 2009
Location: Reaper HAS send control via midi !!!
Posts: 4,031
Default

Thanks a lot, almost there. Is there a way to let the .lua script wait for some time before next command, for example waiting for 500ms or half second? I want to activate the newly opened hackey patterns window, and for this I guess I need to wait a bit, at least worth a try.

This is what I have so far, the idea is having a replacement for above AutoHotkey, using .lua + js_ReaScriptAPI extension:

PHP Code:
hwnd  reaper.JS_Window_Find("Hackey Trackey"false)-- find window by title bar text
if hwnd then -- close the window
   reaper
.JS_WindowMessage_Post(hwnd"WM_CLOSE"0,0,0,0)
   
reaper.Main_OnCommand(41898,0) -- ReaScriptClose all running reaScripts
   
-- open hackey patterns_RSe2f8fd29750dcbc0703bc1d661132968c93e3ab4ScriptHackeyPatterns_exec.lua
   command_id 
reaper.NamedCommandLookup("_RSe2f8fd29750dcbc0703bc1d661132968c93e3ab4")
   
reaper.Main_OnCommand(command_id,0)

   
hwnd2 reaper.JS_Window_Find("Hackey Patterns"false)-- find window by title bar text
   
if hwnd2 then
      reaper
.JS_WindowMessage_Post(hwnd2"WM_ACTIVATE"0,0,0,0)
   
end
else
   
hwnd2 reaper.JS_Window_Find("Hackey Patterns"false)-- find window by title bar text
   
if hwnd2 then -- close the window
      
-- reaper.JS_WindowMessage_Post(hwnd2"WM_CLOSE"0,0,0,0)
      
reaper.Main_OnCommand(41898,0) -- ReaScriptClose all running reaScripts
      
-- open hackey trackey_RS4975f174de39cf66dae73112193ceb783c92adfbScripttracker.lua
      
-- command_id reaper.NamedCommandLookup("_RS4975f174de39cf66dae73112193ceb783c92adfb")
      -- 
reaper.Main_OnCommand(command_id,0)
   
end
end 

Last edited by TonE; 01-24-2019 at 01:58 PM.
TonE is offline   Reply With Quote
Old 01-25-2019, 11:34 AM   #6
Edgemeal
Human being with feelings
 
Edgemeal's Avatar
 
Join Date: Apr 2016
Location: ASU`ogacihC
Posts: 3,913
Default

Quote:
Originally Posted by TonE View Post
Thanks a lot, almost there. Is there a way to let the .lua script wait for some time before next command, for example waiting for 500ms or half second?
If you do need a delay then maybe use a runloop and check elapsed time each pass, something like,..

Code:
function timer()
  local elaspsed = reaper.time_precise() - init_time
  if elaspsed >= wait then
    reaper.ShowConsoleMsg("Times Up!" .. '\n')
    --< secondary code here >-- 
    return -- and exit!
  else -- runloop
    reaper.ShowConsoleMsg(tostring(elaspsed) .. '\n')
    reaper.defer(timer)  
  end  
end

--< initial code here >--

-- wait X seconds, then run other code
wait = 0.500
init_time = reaper.time_precise()
timer()
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 06:28 AM.


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