Quick Help With Autohotkey Script

started 8 months ago | 7 posts | 505 views | topic rss | latest reply
  1. I'm fairly new to the Autohotkey world and I'm having trouble with what should be a pretty basic script. Basically, I want to be able use a script to switch the default audio device to High Definition in Windows 7, which is accomplished by:

    - Running MMSYS.CPL
    - Pressing the down arrow twice
    - Pressing Alt + s
    - Pressing Enter

    I wrote up a simple script to accomplish this, but I must have something wrong in how I'm sending the keystrokes to the active window (the Sound dialog box opens as it should). It looks something like this:

    #z::
    Run MMSYS.CPL
    Send {Down}
    Send {Down}
    Send !s
    Send {Enter}
    return

    Anyone care to point out where I've went wrong? The only thing I could think of was that keystrokes were being sent too rapidly after one another, which I tried to fix with the SetKeyDelay command, but it didn't make a difference. Any help will be greatly appreciated.

    - Optimus


    #
    OptimusComposite
    Reputation:7
    Posted 8 months ago

  2. You should try manually using the Sleep function, like:

    Send {Down}
    Sleep, 10
    Send {Down}

    The problem is probably that the Send function doesn't always use the setkeydelay, depending on the input mode.


    #
    GeekSmith
    Reputation:8
    Posted 8 months ago

  3. Agreed, Sleep is the best option. Keep in mind that the number is in milliseconds, so at least giving Windows a slight delay between keystrokes is the best idea.


    #
    howtogeek
    Reputation:176
    Posted 8 months ago

  4. It could be that it's sending the keys before the window is responding to them - stick a WinWait [name of window] after the run and see how that fares.


    #
    Phoshi
    Reputation:63
    Posted 8 months ago

  5. You guys rock. Adding the Sleep command between each Send took care of the problem right away. Many thanks, guys.


    #
    OptimusComposite
    Reputation:7
    Posted 8 months ago

  6. Glad we could help!


    #
    howtogeek
    Reputation:176
    Posted 8 months ago

  7. Yeah, the sleep command is really useful.


    #
    jj128
    Reputation:39
    Posted 8 months ago

You must log in to post.

Daily Email Updates

Just want the best posts in your inbox for free? Enter your name and email below:

Name:
Email

About This Topic

Our Network
About Productive Geek