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
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.
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.
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.
You guys rock. Adding the Sleep command between each Send took care of the problem right away. Many thanks, guys.
You must log in to post.