Autohotkey script for Play, Pause, Volume Up/Down, Next/Previous


  • administrators

    You'll need to install this on your Windows box to make it work: https://autohotkey.com

    This is my media.ahk autohotkey script:

    Gosub, %1%
    return

    next:
    Send {Media_Next}
    return

    previous:
    Send {Media_Prev}
    return

    pause:
    Send {Media_Play_Pause}
    return

    play:
    Send {Media_Play_Pause}
    return

    stop:
    Send {Media_Stop}
    return

    volup:
    Send {Volume_Up}
    return

    voldown:
    Send {Volume_Down}
    return

    mute:
    Send {Volume_Mute}
    return

    These are the corresponding commands.json entries:

    {"trigger":"Mute","command":"start C:\\autohotkeyscripts\\media.ahk mute","ground":"foreground","voice":"mute"},
    {"trigger":"Volume Up","command":"start C:\\autohotkeyscripts\\media.ahk volup","ground":"foreground","voice":"volume up"},
    {"trigger":"Volume Down","command":"start C:\\autohotkeyscripts\\media.ahk voldown","ground":"foreground","voice":"volume down"},
    {"trigger":"Media Next","command":"start C:\\autohotkeyscripts\\media.ahk next","ground":"foreground","voice":"next"},
    {"trigger":"Media Stop","command":"start C:\\autohotkeyscripts\\media.ahk stop","ground":"foreground","voice":"stop"},
    {"trigger":"Media Previous","command":"start C:\\autohotkeyscripts\\media.ahk previous","ground":"foreground","voice":"previous"},
    {"trigger":"Media Play Pause","command":"start C:\\autohotkeyscripts\\media.ahk pause","ground":"foreground","voice":"pause"},

    NOTE: You don't need a Play and a Pause because they do the same thing - they just toggle between play and pause.

    This is optional, but I'm also using my Raspberry Pi based IR receiver to trigger the above commands with a VCR remote.

    I have these entries in my /etc/lirc/lircrc file on the Pi:

      begin
           prog = irexec
           button = KEY_1
           config = export HOME=/root ; /root/triggertest.sh play downstairs
      end
      begin
           prog = irexec
           button = KEY_2
           config = export HOME=/root ; /root/triggertest.sh notepad downstairs
      end
      begin
           prog = irexec
           button = KEY_PLAY
           config = export HOME=/root ; /root/triggertest.sh "Media Play Pause" downstairs
      end
      begin
           prog = irexec
           button = KEY_PAUSE
           config = export HOME=/root ; /root/triggertest.sh "Media Play Pause" downstairs
      end
      begin
           prog = irexec
           button = KEY_RIGHT
           config = export HOME=/root ; /root/triggertest.sh "Media Next" downstairs
      end
      begin
           prog = irexec
           button = KEY_LEFT
           config = export HOME=/root ; /root/triggertest.sh "Media Previous" downstairs
      end
      begin
           prog = irexec
           button = KEY_STOP
           config = export HOME=/root ; /root/triggertest.sh "Media Stop" downstairs
      end
      begin
           prog = irexec
           button = KEY_UP
           config = export HOME=/root ; /root/triggertest.sh "Volume Up" downstairs
      end
      begin
           prog = irexec
           button = KEY_DOWN
           config = export HOME=/root ; /root/triggertest.sh "Volume Down" downstairs
      end
      begin
           prog = irexec
           button = KEY_MUTE
           config = export HOME=/root ; /root/triggertest.sh "Mute" downstairs
      end


  • @Russ
    Thanks for this! The volup and voldown was unnoticable, only moving 2 on the 1-100 vol scale. I ended up making mine this and now it moves 16 in either direction when I tell my google home to volume up or down.

    volup:
    Send {Volume_Up 8}
    return

    voldown:
    Send {Volume_Down 8}
    return


  • administrators

    @Tim-S, good idea, I like it. Thanks for sharing.



  • Question/Need help -

    I just ran across triggercmd (WOW - great service) and subscribed for a year; however, I have found a very challenging issue. It goes like this :

    Goal: Use my Alexa service to control my itunes application on a remote PC that is connected to my home audio system. Basically I want to trigger things like next track, previous, pause, volume up/down, etc from my echo DOT (I know I can control via my iphone using itunes remote but I want to use Alexa).

    Situation: I have it working with triggercmd and AHT; however, when I disconnect my console (via RDP) my AHT commands don't work - they do fire and log correctly, but they don't do next track, previous, etc. Here are the details:

    • I have a music server that I use to play my music via itunes
    • It is a windows 7 32bit OS (I know, old machine but it works), so I used the manual install of triggercmd (worked fine) and also installed AHT
    • I have the setup working perfectly when I have am RDP'd into the windows 7 machine; however, when I minimize or close the console window the command fires but takes no action.
    • What I have noticed is that either via Alexa or the web triggercmd screen commands via AHT (next, previous, etc) only work when the RDP window is open and showing (minimized fails as well)
    • Strange part is I kept the default triggers like calc and notepad and they work perfectly at all times - even when my RDP session is disconnected. This is the STRANGE part

    So, basically unless my RDP window is up my AHT commands for next, previous, etc won't work even though the the log shows they fire fine.

    Any thoughts??? Also, let me know if you need configs, etc.

    Thanks,
    DaveR


  • administrators

    @drosenth,

    I think the Autohotkey commands would work if you used VNC to connect to the console instead of using RDP.

    Autohotkey is simulating keystrokes which I think are blocked because RDP somehow knows there's no actual keyboard. Maybe it's a Windows security feature.

    Nice job getting the 32bit agent to work. Not everyone can figure that out.



  • Russ,

    THANKS for the quick response - I should have followed-up back when I read this response. I will give VNC a try. The strange thing is even with just a minimized RDP window the AHK commands won't fire. It needs to be visible. But I will try VNC as if I get this working your product solves one of my biggest home automation issues!

    Again, AWESOME product! So very well thought out and versatile - professional all the way!!!

    Thanks,
    Dave R


  • administrators

    Thank you @drosenth !

    I appreciate the feedback.



  • Russ,

    Great news - A simple search of AHK and RDP turned up others having the same issue. I'll find a workaround, for sure, and thanks again FOR AN AWESOME PRODUCT!!

    Your solution is a best kept secret!!! Get the word out!! You have truly taken a great idea and developed nice add-on components that make if very usable (example, the Alexa piece is simple and cool, plus your subscription model - nice).

    So, again, thanks and great work. I will figure this out.

    And if you ever compile your code for Win7 32bit I would be glad to test. The GUI would be nice, but it works great as-is.

    Thanks,
    DaveR

    Link to AHT and RDP issue:

    https://autohotkey.com/board/topic/26749-running-ahk-with-remote-desktop-minimized/


  • administrators

    Thank you @drosenth. I'll take any help I can get spreading the word.



  • Hi Russ, thanks for this.

    I spent the last 5 hours setting up AHK commands for Kodi control and now I'm curious about backing up my triggers.

    On a Windows machine, does backing up the AppData folder suffice?

    If I reformat my PC or accidentally remove a trigger, will the triggers be saved in the cloud? Is there a way to make a backup of them? I created 120 of them and I really don't want to have to do that all again should the worst happen haha.

    Regards.


  • administrators

    @username6, good question. You take a copy of commands.json in the .triggercmddata folder in your profile folder (c:\users\username\.triggercmddata).



  • Hey Russ,

    I have been having trouble with this. I tried getting the directory right but it either cant find the file without using "" or it just opens a CMD with the directory as the title and does not execute code.

    Does the directory have to use \ before the media.ahk and can this be in another directory separate from the C:Drive?

    I am new to this program and cant seem to get the AHK scripts working yet.


  • administrators

    @concretesurfer, this might be the issue:

    When I wrote "start C:\\autohotkeyscripts\\media.ahk stop" above, the context was the commands.json file, but if you're using the GUI Editor, you can skip the double \\'s.

    Just use "start C:\autohotkeyscripts\media.ahk stop" in the GUI Editor.

    Or "start G:\autohotkeyscripts\media.ahk stop", if you're using the G: drive.



  • @russ It works now! It must have been the spaces in my directory.


  • administrators

    @concretesurfer, awesome. Yea if you have spaces you need quotes around your path.


Log in to reply
 

Looks like your connection to TRIGGERcmd Forum was lost, please wait while we try to reconnect.