Reputation: 15186
I was using this Autohotkey script for a while:
; Windows Explorer Save Dialog
; hitting CTRL D goes to address bar, jumps to full desktop path, then goes to filename for the user to override
#IfWinActive ahk_class #32770
^D::
Send !D
String := "%UserProfile%\Desktop"
SendRaw %String%
Send {ENTER}
Send !D
return
#IfWinActive
It stopped working. Probably a Windows 10 update changed something in the file save dialog.
Now using the script above (hitting CTRL+D) still opens the desktop location, but goes to the top right "Desktop Search" (instead of the filename).
Also changing the last Send !D
to Send !N
did not help.
Also Send {TAB}
does not help, Windows ignores it. The focus seems to be stuck to the Search field.
Upvotes: 0
Views: 1432
Reputation: 6489
After the discussion in comments, I was actually able to reproduce the issue you're encountering and found the issue.
The Alt+N
hotkey in the save file dialog to switch focus to file name field indeed doesn't seem to work if the focused control never left any of the text input controls. By setting the focused control at least once to something other than one of the text input controls, then the Alt+N
hotkey seems to work as expected.
Ok, so here's the working code.
^d::
ControlFocus, DirectUIHWND2, A
SendInput, % "!d%userprofile%\Desktop{enter}!n"
return
So first we're focusing the DirectUIHWND2
control, could've used an other control in the save file dialog as well, doesn't matter which one we use.
And if you don't know how to figure out windows' controls, one easy way is to use "Window Spy". It's a neat little AHK script that comes with every AHK installation.
You'll find it from your AHK install directory.
Should be called C:\Program Files\AutoHotkey\WindowSpy.ahk
. Or if you have an older AHK installation, it may also be a compiled script file named AU3_Spy.exe
(or something like that, I forget)
And the A
parameter in the ControlFocus
command means the active window.
And then I used just one send command. No need to use multiple send commands, or create some variable, as you do in your code.
And also used !d
and !n
instead of !D
and !N
.
Don't use capital letters in send commands, unless you actually want them.
!D
and !N
actually send Ctrl+Shift+D
and Ctrl+Shift+N
, instead of Alt+D
and Alt+N
, which is what I assume you actually were after.
Also, used SendInput
instead of just Send
. SendInput
is the preferred method due to it being faster and more reliable (more about this from the documentation)
Though, one concern I have, is maybe it could even be too fast. Seems work fine for me every single time, but if you were to have trouble, you can maybe split it up to multiple commands, adding a bit of Sleep
in between. Or maybe could even switch back to Send
and use SetKeyDelay
.
Another approach for this, could be with using control set -commands.
E.g. first focusing a control, as I did in my code, and then using e.g ControlSetText
.
Upvotes: 3