AutoHotKey and Moho Menu Selection Question

Moho allows users to write new tools and plugins. Discuss scripting ideas and problems here.

Moderators: Víctor Paredes, Belgarath, slowtiger

User avatar
Greenlaw
Posts: 9191
Joined: Mon Jun 19, 2006 5:45 pm
Location: Los Angeles
Contact:

Re: AutoHotKey and Moho Menu Selection Question

Post by Greenlaw »

I finally got back to this project over the long weekend. I re-configured the panel layout and added a few new buttons. I'll probably never use one or two of them, but I think other users may find them useful.

Anyway, the panel works much better now except...

Wes, or anybody else who knows AHK, can you look at this snippet of code for me?

SetTitleMatchMode 2
WinActivate, - Moho ahk_class LM_Wnd
SetKeyDelay, 1000 ; Delay necessary for Ctrl Shift R (Preview Anim) to initiate
Send {Home}
Send ^+r:: ; Ctrl Shift R

This should be super simple: all the above is supposed to do is send two 'default' shortcuts to Moho so it can Reset (to fit the workspace to window) and then run a Preview Animation. At work I use a Wacom OSC that simply sends Home and Ctrl Shift R with one button, and this works perfectly, but with the Autohotkey button using the above code to send the same shortcuts, I get about 24 frames in when the player opens with an incomplete render.

What I think is happening is that once the KeyDelay runs out after the second Send command, the Preview Animation is interrupted by AHK (on this computer it's always at around 24 frames.) But extending the delay time isn't a solution because I don't know how long the Preview Animation render will take for any given project.

Is there another command I can use that makes AHK wait until the Preview Animation is completed? In looking through the docs I found WinWaitNotActive but I don't understand how to use it properly or know if it's even appropriate to this situation.

Any ideas? Thanks in advance for any helpful advice.

I have one other AHK question regarding a smaller problem but I'll save it for later. I'd really like to take care of the above issue first.
Last edited by Greenlaw on Tue Feb 20, 2018 8:50 pm, edited 1 time in total.
User avatar
Greenlaw
Posts: 9191
Joined: Mon Jun 19, 2006 5:45 pm
Location: Los Angeles
Contact:

Re: AutoHotKey and Moho Menu Selection Question

Post by Greenlaw »

I got it! The solution is simple: remove the [::] after the [^+r]. This seems to allow Preview Animation to finish. But is it proper? Either way, I'm going with it for now.

I'll post my next question at lunch.

(Note: In my rush to type my original post quickly, I incorrectly transcribed the snippet. The snippet has been updated to reflect what I intended to post.)
Last edited by Greenlaw on Tue Feb 20, 2018 9:30 pm, edited 4 times in total.
User avatar
Greenlaw
Posts: 9191
Joined: Mon Jun 19, 2006 5:45 pm
Location: Los Angeles
Contact:

Re: AutoHotKey and Moho Menu Selection Question

Post by Greenlaw »

I see that [::] is used to remap a key, which I don't really need here because I want to use the default Moho shortcut. I'm guessing that leaving this blank tells AHK to "stick with the original key mapping"? Even so, it seems to interrupt the Preview Animation process.

Is it safe to assume leaving [::] out entirely isn't hurting anything? (I know I should be asking in the AHK forum but this seems to be a Moho-specific thing with Preview Animation.)
User avatar
synthsin75
Posts: 9934
Joined: Mon Jan 14, 2008 11:20 pm
Location: Oklahoma
Contact:

Re: AutoHotKey and Moho Menu Selection Question

Post by synthsin75 »

Greenlaw wrote:I see that [::] is used to remap a key, which I don't really need here because I want to use the default Moho shortcut. I'm guessing that leaving this blank tells AHK to "stick with the original key mapping"? Even so, it seems to interrupt the Preview Animation process.

Is it safe to assume leaving [::] out entirely isn't hurting anything? (I know I should be asking in the AHK forum but this seems to be a Moho-specific thing with Preview Animation.)
Yeah, there's no reason I can think of to use "::" in a Send command, unless sending those characters. That is used to define what key(s) activate the following hotkey commands. So (if I remember my AHK syntax):

Code: Select all

SetTitleMatchMode 2
WinActivate, - Moho ahk_class LM_Wnd
SetKeyDelay, 1000 ; Delay necessary for Ctrl Shift R (Preview Anim) to initiate
$^+r::
$Home::
Send {Home}
Send ^+r ; Ctrl Shift R
return
This would make either Home or Ctrl+Shift+R send both commands. I don't know what key/key combo you have your Wacom sending to activate the AHK script.
The "$" are needed here to allow the hotkey to send itself without creating an infinite loop of its send command reactivating the hotkey every time. I'm not sure you even need the key delay.

Yeah, I would post Moho specific AHK questions here. As long as someone here can help anyway.
User avatar
Greenlaw
Posts: 9191
Joined: Mon Jun 19, 2006 5:45 pm
Location: Los Angeles
Contact:

Re: AutoHotKey and Moho Menu Selection Question

Post by Greenlaw »

Hmm...removing the [::] also means I no longer need the delay (was set to 1000; changed it back to 0.)

This also fixed my 'small' problem, which was that sending [^e::] to open the Export Animation window caused Moho on my mobile computer to beep unnecessarily. Removing [::] allows Moho to open the window without the beep. This makes me wonder if I should remove [::] elsewhere in the script. Curiously, my workstation at work doesn't beep when I run [Send ^e::], instead it opens the window as expected silently.

Also, other AHK to Moho commands, like [Send ^b::], do not generate a 'beep' on my mobile computer. Not sure why the [^e::] shortcut beeps on this computer. My understanding is that the beep probably means I'm sending a shortcut that doesn't exist in the program but obviously it does exist since it opens the window. Weird.

Anyway, I guess I'm almost ready to release this tool.
Last edited by Greenlaw on Wed Feb 21, 2018 1:39 am, edited 3 times in total.
User avatar
Greenlaw
Posts: 9191
Joined: Mon Jun 19, 2006 5:45 pm
Location: Los Angeles
Contact:

Re: AutoHotKey and Moho Menu Selection Question

Post by Greenlaw »

Hey Wes,

I just saw your reply. Thanks!

I'll read it through and process the info now. :)
User avatar
Greenlaw
Posts: 9191
Joined: Mon Jun 19, 2006 5:45 pm
Location: Los Angeles
Contact:

Re: AutoHotKey and Moho Menu Selection Question

Post by Greenlaw »

synthsin75 wrote:This would make either Home or Ctrl+Shift+R send both commands. I don't know what key/key combo you have your Wacom sending to activate the AHK script.
Sorry, I should have explained: This isn't used with the Wacom OSC, it's meant to replace it.

Thanks for explaining the use of [$] and other parts of your example. It's very helpful.

Some day, I may actually know what I'm doing. :)
User avatar
Greenlaw
Posts: 9191
Joined: Mon Jun 19, 2006 5:45 pm
Location: Los Angeles
Contact:

Re: AutoHotKey and Moho Menu Selection Question

Post by Greenlaw »

Quickly tested the panel and all appears good now. Thanks for your help Wes!

Regarding the [SetKeyDelay, 0], I read that this can improve the response. That said, I realize what I'm doing here is so basic, it probably doesn't matter. But just for kicks, I'll try removing all the [SetKeyDelay]s and see if I notice any difference.

I'll run it through a 'real-world' test tonight, and record install/usage videos tonight. If all goes well, I'll post the tool soon after.
User avatar
Greenlaw
Posts: 9191
Joined: Mon Jun 19, 2006 5:45 pm
Location: Los Angeles
Contact:

Re: AutoHotKey and Moho Menu Selection Question

Post by Greenlaw »

I noticed one odd thing with my AHK Preview Animation button. It plays through the range from start to finish like it's supposed to, but then Moho starts 'playing' from 0 again until it's back to the frame where I was when I clicked the button. Not a big deal but it's weird. (Naturally, if I'm already on 0, it doesn't do this.)

I'm not going to let that stop me from releasing it but would you mind taking a look at it for me? I'll PM you a link tonight.
Last edited by Greenlaw on Wed Feb 21, 2018 1:38 am, edited 1 time in total.
User avatar
Greenlaw
Posts: 9191
Joined: Mon Jun 19, 2006 5:45 pm
Location: Los Angeles
Contact:

Re: AutoHotKey and Moho Menu Selection Question

Post by Greenlaw »

If I give it a tiny amount of SetKeyDelay, it works.

I think this delay is just killing the unnecessary 'second play' pass with a timeout but only after it's run completely through the render pass. Whatever works I guess.

I need to test it more this evening to be sure this works for any frame range. (Edit: checked this before lunch ended. It works!)
Last edited by Greenlaw on Wed Feb 21, 2018 1:26 am, edited 4 times in total.
User avatar
synthsin75
Posts: 9934
Joined: Mon Jan 14, 2008 11:20 pm
Location: Oklahoma
Contact:

Re: AutoHotKey and Moho Menu Selection Question

Post by synthsin75 »

Greenlaw wrote:I noticed one odd thing with my AHK Preview Animation button. It plays through the range from start to finish like it's supposed, but then Moho starts 'playing' from 0 again until it's back to the frame where I was when I clicked the button. Not a big deal but it's weird. (Naturally, if I'm already on 0, it doesn't do this.)

I'm not going to let that stop me from releasing it but would you mind taking a look at it for me? I'll PM you a link tonight.
Yeah, I'd be happy to go over the code and test it for you. Easy to end up doing unnecessary stuff in a script, especially while learning AHK.
Post Reply