Luis Diaz
asked on
Authotkey: send keys if a windows explorer is active
Hello experts,
I would like to send specific specific keys exclusively for windows explorer example:
zip file
The idea is to add a loop if windows explorer windows is open if not don't send the key.
The problem is that I cannot loop on the windows title as it is not always the same. Either on windows ID.
Do you know how can I manage this?
Thank you for your help.
I would like to send specific specific keys exclusively for windows explorer example:
zip file
+F7::
Send, +{F10}
Sleep, 5
Send, 7
The idea is to add a loop if windows explorer windows is open if not don't send the key.
The problem is that I cannot loop on the windows title as it is not always the same. Either on windows ID.
Do you know how can I manage this?
Thank you for your help.
ASKER
Thank you Joe, exactly what I need I use win 10 as OS. I can't test it right know but I will keep you informed.
I didn't know that you can loop on windows class.
I take the opportunity to ask you a complementary question about windows class, do you know windows class of Excel/Word/Power point/Cmd/Powershell Windows class? If not could you please provide an ahk to display ahk windows class?
Thank you Joe.
I didn't know that you can loop on windows class.
I take the opportunity to ask you a complementary question about windows class, do you know windows class of Excel/Word/Power point/Cmd/Powershell Windows class? If not could you please provide an ahk to display ahk windows class?
Thank you Joe.
You're welcome, Luis. Seems that I can't get you to stop using the word "loop" for this. :)
> I didn't know that you can loop on windows class.
There are many AutoHotkey statements that have WinTitle as a parameter. It is an extremely important concept. I suggest that you study the documentation on it well:
https://www.autohotkey.com/docs/misc/WinTitle.htm
You will see there that Window Class is one of the ways that WinTitle may be specified:
https://www.autohotkey.com/docs/misc/WinTitle.htm#ahk_class
> please provide an ahk to display ahk windows class
This will show the Class, Title, and Process Name of the active window:
The hotkey is Shift+F8...of course, make it whatever you want.
Btw, all of the #IfWin directives are positional, i.e., they affect all hotkeys and hotstrings beneath them in the script. To turn off the context sensitivity of an #IfWin directive, code the directive without any parameters. For the code in my previous post, that would be:
https://www.autohotkey.com/docs/commands/_If.htm
Those hotkeys/hotstrings perform a different action (or no action) based on the result of evaluating an expression.
Regards, Joe
> I didn't know that you can loop on windows class.
There are many AutoHotkey statements that have WinTitle as a parameter. It is an extremely important concept. I suggest that you study the documentation on it well:
https://www.autohotkey.com/docs/misc/WinTitle.htm
You will see there that Window Class is one of the ways that WinTitle may be specified:
https://www.autohotkey.com/docs/misc/WinTitle.htm#ahk_class
> please provide an ahk to display ahk windows class
This will show the Class, Title, and Process Name of the active window:
+F8::
WinGetClass,Class,A
WinGetTitle,Title,A
WinGet,Process,ProcessName,A
MsgBox,4160,Active Window,Class=%Class%`n`nTitle=%Title%`n`nProcess Name=%Process%
Return
The hotkey is Shift+F8...of course, make it whatever you want.
Btw, all of the #IfWin directives are positional, i.e., they affect all hotkeys and hotstrings beneath them in the script. To turn off the context sensitivity of an #IfWin directive, code the directive without any parameters. For the code in my previous post, that would be:
#IfWinActive
Also, you can create context-sensitive hotkeys and hotstrings with the #If directive. You may learn about that here:https://www.autohotkey.com/docs/commands/_If.htm
Those hotkeys/hotstrings perform a different action (or no action) based on the result of evaluating an expression.
Regards, Joe
ASKER
Thank you Joe, I will take a look today and I will keep you informed.
OK, I'll be here.
ASKER
Joe, I tested and it works!
I also tested windows attributes and it also works. Extremely beneficial if I want to restrict shortcut for specific application and avoid shortcuts keys clash.
I also took the opportunity to add id attribute to have all the windows attributes in one ahk.
Thank you for your help. (this was generated with thx :-)
I also tested windows attributes and it also works. Extremely beneficial if I want to restrict shortcut for specific application and avoid shortcuts keys clash.
I also took the opportunity to add id attribute to have all the windows attributes in one ahk.
+F8::
WinGetClass,Class,A
WinGetTitle,Title,A
WinGet,Process,ProcessName,A
WinGet,active_id, ID, A
;~ MsgBox, The active window's ID is "%active_id%".
MsgBox,4160,Active Window,Class=%Class%`n`nTitle=%Title%`n`nProcess Name=%Process%`n`nID=%active_id%
Return
Concerning context sensitive, Should I finish my ahk with: #If
Return
?Thank you for your help. (this was generated with thx :-)
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Ok, noted Joe.
Regarding context sensitivity I also used some keys to send special characters as following:
Example I activate capslocks and I forgot to turn it off, should this affect ahk located bellow such as running application or hotstrings?
Thank you for your help.
Regarding context sensitivity I also used some keys to send special characters as following:
#if getkeystate("capslock", "t")=0
+a::send {asc 160}
;clash with gmail removal +e::send {asc 130}
+i::send {asc 161}
+o::send {asc 162}
+u::send {asc 163}
+n::send {asc 164}
+#?::send {asc 168}
#!::send {asc 173}
#if getkeystate("capslock", "t")=1
;clash with gmail removal +e::send {asc 144}
+i::send {asc 214}
+n::send {asc 165}
+o::send {asc 224}
+u::send {asc 233}
+a::send {asc 181}
#if
Return
#if placed prior to return can affect the rest of commands bellow?Example I activate capslocks and I forgot to turn it off, should this affect ahk located bellow such as running application or hotstrings?
Thank you for your help.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Joe,
Sorry for the delay.
I have set up as recommended
Thank you for your help.
Sorry for the delay.
I have set up as recommended
#if getkeystate("capslock", "t")=0
+a::send {asc 160}
;clash with gmail removal +e::send {asc 130}
+i::send {asc 161}
+o::send {asc 162}
+u::send {asc 163}
+n::send {asc 164}
+#?::send {asc 168}
#!::send {asc 173}
#if getkeystate("capslock", "t")=1
;clash with gmail removal +e::send {asc 144}
+i::send {asc 214}
+n::send {asc 165}
+o::send {asc 224}
+u::send {asc 233}
+a::send {asc 181}
#if
Return
By ending every if condition with #if and also placing scripts which use context sensitivity at the end (at the bottom) in order to avoid affecting in case of unintentional caps lock on/off.Thank you for your help.
You're welcome, Luis. Is it working to your satisfaction now? If so, select one or more posts as the solution; if not, let me know what isn't working well. Regards, Joe
ASKER
Done Joe, thank you again.
Great! Thanks for the update and for closing the question. Cheers, Joe
This AutoHotkey script will do what you want:
Open in new window
I haven't tested your code under +F7:: (and I don't use Windows/File Explorer as my file manager), but the line that I wrote for you will cause +F7 to fire only when Windows/File Explorer is the active window. Btw, the Class for Windows versions prior to Vista is ExploreWClass, but I recollect from previous questions that you're on W10. Regards, Joe