Old 01-12-2009, 01:44 AM   #1
frog_jr
Human being with feelings
 
frog_jr's Avatar
 
Join Date: Sep 2007
Location: Here at the Western World
Posts: 1,253
Default Custom Commands Question

Hi, I think I may have asked something like this a few months ago. Is there a way yet of executing a an action or command from ahk using its command number found on the right hand column in the actions window?

If not, would this be a good feature request?
frog_jr is offline   Reply With Quote
Old 01-12-2009, 02:30 AM   #2
Xenakios
Human being with feelings
 
Xenakios's Avatar
 
Join Date: Feb 2007
Location: Oulu, Finland
Posts: 8,062
Default

If AHK supports sending raw Windows messages to the Reaper main window, it should be possible.

In the Windows C API the call is like :

SendMessage(hReapermainWindow,WM_COMMAND,CommandID ,0);

Which means the target window is hReapermainWindow, which needs to be the correct window handle of Reaper's main window, WM_COMMAND is the message type that is sent, CommandID would be the number found from the actions list and 0 is for an unused (here) parameter. AHK will probably have a different syntax for sending such messages, if it supports it.
__________________
I am no longer part of the REAPER community. Please don't contact me with any REAPER-related issues.
Xenakios is offline   Reply With Quote
Old 01-12-2009, 04:29 AM   #3
frog_jr
Human being with feelings
 
frog_jr's Avatar
 
Join Date: Sep 2007
Location: Here at the Western World
Posts: 1,253
Default

Xenakios, thanks very much for that. I'm trying but nothing so far. I'm asking around at the ahk forum too. Some of them are very knowledgeable.

I'm going to have to quit for the evening though. Ahk has a command called SendMessage and one called PostMessage, and I couldn't get either of them to work so far. The ahk documentation says it supports Windows messages, but when I go to the list of them I see they are all apparently hex base numbers. I tried converting the Reaper command number to hex just to see if it would work and no luck.

Thanks!
frog_jr is offline   Reply With Quote
Old 01-12-2009, 04:59 AM   #4
Xenakios
Human being with feelings
 
Xenakios's Avatar
 
Join Date: Feb 2007
Location: Oulu, Finland
Posts: 8,062
Default

Quote:
Originally Posted by frog_jr View Post
Xenakios, thanks very much for that. I'm trying but nothing so far. I'm asking around at the ahk forum too. Some of them are very knowledgeable.

I'm going to have to quit for the evening though. Ahk has a command called SendMessage and one called PostMessage, and I couldn't get either of them to work so far. The ahk documentation says it supports Windows messages, but when I go to the list of them I see they are all apparently hex base numbers. I tried converting the Reaper command number to hex just to see if it would work and no luck.

Thanks!
Msg in the AHK function (Send/PostMessage) needs to be the equivalent of WM_COMMAND (which appears to be the hex value of 0x0111), wParam is the Reaper command ID as an integer number, lparam should be 0. Take care you manage to send the message to the correct window, which should be Reaper's. (Btw, the difference between Send/PostMessage is that SendMessage will block the AHK scrip until the destination window has actually processed the message, which most often is the preferable way to do things, as not to mess up the order in which things get executed.)
__________________
I am no longer part of the REAPER community. Please don't contact me with any REAPER-related issues.
Xenakios is offline   Reply With Quote
Old 01-12-2009, 05:11 AM   #5
frog_jr
Human being with feelings
 
frog_jr's Avatar
 
Join Date: Sep 2007
Location: Here at the Western World
Posts: 1,253
Default

Success! !!!!!!!!!

Syntax is right!

^8::
SendMessage,0x0111,40021,0,,ahk_class REAPERwnd
Return

Means that Ctrl-8 opens project settings! Yesssss!

Cheers, frog_jr
frog_jr is offline   Reply With Quote
Old 01-12-2009, 10:31 AM   #6
frog_jr
Human being with feelings
 
frog_jr's Avatar
 
Join Date: Sep 2007
Location: Here at the Western World
Posts: 1,253
Default

One of my mst helpful instructors over at the ahk forum, SKAN, provided a list of Reaper commands pre-arranged in a menu to include in any script. They are available at http://www.autohotkey.com/forum/view...=242998#242998

He used the following command syntax:
;-----------------------------------------------------
#IfWinActive, ahk_class REAPERwnd
^+#5::PostMessage, 0x111,40015,0,, A ; Render to File
^+#6::PostMessage, 0x111,40007,0,, A ; About Reaper
#IfWinActive
;-----------------------------------------------------
frog_jr is offline   Reply With Quote
Old 01-12-2009, 11:32 AM   #7
frog_jr
Human being with feelings
 
frog_jr's Avatar
 
Join Date: Sep 2007
Location: Here at the Western World
Posts: 1,253
Default

This thread, combined with this one:

http://forum.cockos.com/showthread.php?t=23236

is enough to now make my head explode! Thanks, I'll have to put on the hat with the little aluminum cooling fins.
frog_jr is offline   Reply With Quote
Old 01-12-2009, 06:58 PM   #8
Bevosss
Human being with feelings
 
Bevosss's Avatar
 
Join Date: Feb 2007
Location: Sydney Oz
Posts: 8,480
Default

Awesome frog! Fantastic work here.

There is a huge advantage using direct scripts vs loading separate keymaps in the speed of implementation, in that you can load a new 'keymap' with a keystroke, and revert just as fast. Plus, you only need to update your current map with new keystroke changes, unlike if you have several eg a tempo-mapping keymap or others in addition to your main keymap. There's been a few bugs in the keymap implementation before such as doubled up actions when importing, so this seems a lot safer to use, with much less chance of corrupting your keymap.

Very exciting stuff indeed! One thing that bugged me about ahk vs the plugin extensions was, it was operating Reaper from outside or 'on the surface', without a fast direct windows command connection...that's all changed now!

Just a query also...how do you implement that menu list from SKAN? Can you give me something to cut and paste into a script to use it?

Cheers!
__________________
The media are misleading the public about Syria:
https://www.bostonglobe.com/opinion/...tcK/story.html
Bevosss is offline   Reply With Quote
Old 01-12-2009, 08:44 PM   #9
frog_jr
Human being with feelings
 
frog_jr's Avatar
 
Join Date: Sep 2007
Location: Here at the Western World
Posts: 1,253
Default

Well I think that SKAN was showing off his impressive skilz here. If you read our exchange and note the times, you may notice that he downloaded and installed REAPER, queried it for all these codes and posted them to me within minutes. They are all the codes from Reaper's main taskbar. I can imagine him knocking together a script to get all that info inside of 10 minutes. The wise heads at the ahk forums may answer a question if it's challenging enough to them.

To make a GUI that would use them, you use the ahk Menu command, set up a command for each one of those menu items like so:

40021:
SendMessage,0x0111,40021,0,,ahk_class REAPERwnd
Return

Or I'm sure there are even better ways of doing it but I've only written a couple simple taskbar menus in ahk so far.

If you want another simple example, try downloading my little ReaperNotes script, which has a simple menu, and will soon have more menu entries. Among other things, a simple "execute command number in Reaper" will be included soon. Something like this (try it!):
Quote:
;-----------------------------------------------------
^+#F4:: ;;Ctrl-Alt-Shft-Win-F4 to send to main window
INputBox, CmdNm, ID NUMBER for Command, Enter Command ID number to send to REAPER., ,340,240
If ErrorLevel
{
MsgBox, Cancel was pressed.
Return
}
Else
SendMessage,0x0111,%CmdNm%,0,,ahk_class REAPERwnd
Return

^+#F5:: ;;Ctrl-Alt-Shft-Win-F5 to send to MIDI window
INputBox, CmdNm, ID NUMBER for Command, Enter Command ID number to the MIDI editor., ,340,240
If ErrorLevel
{
MsgBox, Cancel was pressed.
Return
}
Else
SendMessage,0x0111,%CmdNm%,0,,ahk_class REAPERmidieditorwnd
Return
;-----------------------------------------------------
Further infos:

AHK command reference - look up "menu" comand there:
http://www.autohotkey.com/docs/commands.htm

AHK Gui page:
http://www.autohotkey.com/docs/commands/Gui.htm

Last edited by frog_jr; 01-12-2009 at 08:46 PM.
frog_jr is offline   Reply With Quote
Old 01-12-2009, 08:49 PM   #10
frog_jr
Human being with feelings
 
frog_jr's Avatar
 
Join Date: Sep 2007
Location: Here at the Western World
Posts: 1,253
Default

And this simple ahk command copies highlighted Reaper command # to clipboard from anywhere, and executes it in Reaper. Make sure it's the right text you have highlighted!

Quote:
^+#P::
Sendinput, ^c
WinActivate ahk_class REAPERwnd
SendMessage,0x0111,%Clipboard%,0,,ahk_class REAPERwnd ;
Return

Last edited by frog_jr; 01-12-2009 at 08:57 PM.
frog_jr is offline   Reply With Quote
Old 10-16-2012, 09:03 AM   #11
flipotto
Human being with feelings
 
flipotto's Avatar
 
Join Date: Feb 2007
Location: VA
Posts: 887
Default

Quote:
Originally Posted by frog_jr View Post
One of my mst helpful instructors over at the ahk forum, SKAN, provided a list of Reaper commands pre-arranged in a menu to include in any script. They are available at http://www.autohotkey.com/forum/view...=242998#242998

He used the following command syntax:
;-----------------------------------------------------
#IfWinActive, ahk_class REAPERwnd
^+#5::PostMessage, 0x111,40015,0,, A ; Render to File
^+#6::PostMessage, 0x111,40007,0,, A ; About Reaper
#IfWinActive
;-----------------------------------------------------
So how to I make his list actually show?
I created an ahk file from his list (cited above)
How do I actually call up the list?
I get an error if I try to run the file
flipotto is offline   Reply With Quote
Old 01-09-2017, 12:09 PM   #12
aspiringSynthesisingAlch
Human being with feelings
 
Join Date: Feb 2014
Posts: 309
Default heads-up ! ReaAHK titbits!!!!

Quote:
Originally Posted by frog_jr View Post
One of my mst helpful instructors over at the ahk forum, SKAN, provided a list of Reaper commands pre-arranged in a menu to include in any script. They are available at http://www.autohotkey.com/forum/view...=242998#242998

He used the following command syntax:
;-----------------------------------------------------
#IfWinActive, ahk_class REAPERwnd
^+#5::PostMessage, 0x111,40015,0,, A ; Render to File
^+#6::PostMessage, 0x111,40007,0,, A ; About Reaper
#IfWinActive
;-----------------------------------------------------

Dr. Frog, Jr! Sir!!!! Thank you : ) (along with everyone else that helped 'the cause' : )

Been after these for a long time ...

quick q, for anyone in the know. is there a rule-of-thumb, re when to use
PostMessage vs SendMessage ? Or is one best regardless?

Code:
^8::
SendMessage,0x0111,40021,0,,ahk_class REAPERwnd
Return
many many many thanks
aspiringSynthesisingAlch 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:27 AM.


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