Jump to content


Photo

pid and window handling query


  • Please log in to reply
2 replies to this topic

#1 Stilez

Stilez
  • Members
  • 2 posts

Posted 23 January 2011 - 10:42 PM

I'm trying to use Autohotkey to improve Win+E in Windows 7. I'm hoping to create a script that opens a standard Windows Explorer instance, showing all drives collapsed in the tree, with the "C:" drive selected and ready to go.

The script I have sort of works but I'm a complete newcomer and would like to improve it.

#HotkeyInterval 1000
#MaxHotkeysPerInterval 15
#MaxThreadsBuffer on
#MaxThreadsPerHotkey 50
#e::
run, "%windir%\explorer.exe" c:\, c:\, , PID
WinWait, ahk_pid %PID%,,1
sendinput +{tab}{left}

Known problems with the script so far:
[*:3hqsztih] Winwait isn't behaving as expected. I originally tried "WinWait, ahk_pid %PID%,,10" to allow time if the system was under heavy load, but instead of waiting for a maximum of 10 seconds, it waited 10 seconds even if the window appeared quickly. So I changed 10 to 1 but I can't seem to get it to act as a maximum timeout. ("If a matching window comes into existence, the command will not wait for Seconds to expire")
[*:3hqsztih] If other window and process activity is going on, for example Win+E twice quickly, or other changes to window focus etc, then sometimes the right window doesn't seem to get the "send" keystrokes.
If anyone can help I'd appreciate it!

#2 Leef_me

Leef_me
  • Moderators
  • 7704 posts

Posted 24 January 2011 - 04:23 AM

Unlees you need them for a another portion of your script, disable the first 4 lines (before your hotkey)

to prevent multiple invocations of your hotkey, consider using either of the following

#e:: 
KeyWait, e
#e up::

>>but I can't seem to get it to act as a maximum timeout
if the winwait takes 10 seconds, it is NOT finding the window, it IS WORKING as a maximum

I added this script to your script, and found that the PID 'run' and the pid of the window displayed were not the same.
f1::
mousegetpos,,,OutputVarWin
WinGet, active_pid, PID, ahk_id %OutputVarWin%
tooltip, you ran this pid %PID% `r`nthe mouse is over this pid %active_pid% 
return


#3 Stilez

Stilez
  • Members
  • 2 posts

Posted 24 January 2011 - 05:22 PM

The script needs to open a new windows explorer window, then send some keys to it.

Presumably based on your checking, I have to identify the right window/process, ensure that the newly opened window is active before the key send, and take care that the keys act upon that window.

If my existing code isn't doing this, then I'm not sure how to do it instead. Can you help figure code that does this properly?