Paaing multiple parameters to this function? - autohotkey

I have been messing with this amazing function I found on the old forums. There is not much information on it.
I tried to figure it out on my own but to no avail. I could really use some help with. Here is the link to it.
So far I can only seem to pass one parameter to it, but reading his brief description it seems possible to pass multiple parameters to it. If I am mistaken please let me know.
I would like to invoke the function like this WinGetAll("Title", Class', 'Hwnd', 'Process', 'PID') , so that it will return all the properties of a window per line:
[Window #1 Title],[Window #1 Class], [Window #1 Hwn], [Window #1 Process], [Window #1 PID]
[Window #2 Title],[Window #2 Class], [Window #2 Hwn], [Window #2 Process], [Window #2 PID]
[Window #3 Title],[Window #3 Class], [Window #3 Hwn], [Window #3 Process], [Window #3 PID]
<etc etc >
With my experimentations, I was only able to use two parameters at once:
WinTitles := WinGetAll("Title", "On")
WinTitles := WinGetAll("Title", "Off")
I am very new to AHK, There may be much better solutions. If so please let me know.
I just need a reliabe way to get every window and its properties listed in a single line:
[Window #1 Title],[Window #1 Class], [Window #1 Hwn], [Window #1 Process], [Window #1 PID]
With the option to hide system windows such as svchost.exe / csrss.exe / services.exe etc
Any help would be greatly appreciated!

Try this
WinGet, id, list
Loop, %id%
{
this_ID := id%A_Index%
WinGet, exStyle, exStyle, ahk_id %this_ID%
If !(exStyle & 0x100)
continue
WinGetTitle, title, ahk_id %this_ID%
If (title = "")
continue
WinGetClass, class, ahk_id %this_ID%
WinGet, PID, PID, ahk_id %this_ID%
WinGet, ProcessName, ProcessName, ahk_id %this_ID%
Index++
wins .= "Window #" Index . ":`ntitle = " title "`n" "class =" class "`n" "hwnd =" this_ID "`n" "PID =" PID "`n" "ProcessName =" ProcessName "`n`n"
}
MsgBox, % wins

Related

How to get the Microsoft Teams active meeting window with AutoHotkey?

In the Microsoft Teams Windows Client I would like to be able to identify with AutoHotkey the current active meeting window.
Consider that you can have several Teams window opened (popped-out chats, main window, several meeting windows with some on hold,...)
(Background: I want to do this to be able to send meeting specific actions hotkeys.)
I have come to another approach based on FindText to exclude any user prompt.
It check in the Teams windows if a UI Element like Leave and Resume are available to 100% exclude the wrong window.
See detailed explanation in this post: https://tdalon.blogspot.com/2021/04/ahk-get-teams-meeting-window.html
with screencast.
And here the code in gist: https://gist.github.com/tdalon/d376a2ac395a41c5453904222cbcb529
Extract below:
Teams_GetMeetingWindow(useFindText:="" , restore := True){
; See implementation explanations here:
; https://tdalon.blogspot.com/2021/04/ahk-get-teams-meeting-window.html
; https://tdalon.blogspot.com/2020/10/get-teams-window-ahk.html
If (useFindText="")
useFindText := PowerTools_GetParam("TeamsMeetingWinUseFindText") ; Default 1
If (useFindText) {
If (restore)
WinGet, curWinId, ID, A
ResumeText:="|<>*138$51.zzzzzzzzw3zzzzzzzUDzzzzzzwtzzzzzzzbA64NU1kQ1423A04FUtUQNa8aAX0EXAlY1a9zUNaAbwt4Y0AlYHb4461aAkTzzzzzzzzU" ; FindText for Resume
LeaveText:="|<>*168$66.zzzzzzzzzzzzzzzzDzzzzzy01zzDzzzzzs00TzDzzzzzk00DzDkkFW3U7k7zDUG9YFUDk7zD6T9YlUTs7zD0E841kTs7zD7nAAzszwDz022AAHzzzzz0UECS3zzzzzzzzzzzU"
}
WinGet, Win, List, ahk_exe Teams.exe
TeamsMainWinId := Teams_GetMainWindow()
TeamsMeetingWinId := PowerTools_RegRead("TeamsMeetingWinId")
WinCount := 0
Select := 0
Loop %Win% {
WinId := Win%A_Index%
If (WinId = TeamsMainWinId) { ; Exclude Main Teams Window
;WinGetTitle, Title, % "ahk_id " WinId
;MsgBox %Title%
Continue
}
WinGetTitle, Title, % "ahk_id " WinId
IfEqual, Title,, Continue
Title := StrReplace(Title," | Microsoft Teams","")
If RegExMatch(Title,"^[^\s]*\s?[^\s]*,[^\s]*\s?[^\s]*$") or RegExMatch(Title,"^[^\s]*\s?[^\s]*,[^\s]*\s?[^\s]*\([^\s\(\)]*\)$") ; Exclude windows with , in the title (Popped-out 1-1 chat) and max two words before , Name, Firstname
Continue
If RegExMatch(Title,"^Microsoft Teams Call in progress*") or RegExMatch(Title,"^Microsoft Teams Notification*") or RegExMatch(Title,"^Screen sharing toolbar*")
Continue
If (useFindText) {
; Exclude window with no Leave element
WinActivate, ahk_id %WinId%
If !(ok:=FindText(,,,, 0, 0, LeaveText,,0)) {
Continue
}
; Final check - exclude window with Resume element = On hold meetings
If (ok:=FindText(,,,, 0, 0, ResumeText,,0)) {
Continue
}
}
WinList .= ( (WinList<>"") ? "|" : "" ) Title " {" WinId "}"
WinCount++
; Select by default last meeting window used
If WinId = %TeamsMeetingWinId%
Select := WinCount
} ; End Loop
If (WinCount = 0)
return
If (WinCount = 1) { ; only one other window
RegExMatch(WinList,"\{([^}]*)\}$",WinId)
TeamsMeetingWinId := WinId1
PowerTools_RegWrite("TeamsMeetingWinId",TeamsMeetingWinId)
return TeamsMeetingWinId
}
If (restore)
WinActivate, ahk_id %curWinId%
LB := WinListBox("Teams: Meeting Window", "Select your current Teams Meeting Window:" , WinList, Select)
RegExMatch(LB,"\{([^}]*)\}$",WinId)
TeamsMeetingWinId := WinId1
PowerTools_RegWrite("TeamsMeetingWinId",TeamsMeetingWinId)
return TeamsMeetingWinId
} ; eofun
I have tried to find it out by the Window Title, but Teams does not name Meeting windows in a particular way.
I could find with AccViewer that the Main Team Window has its name ending with "| Microsoft Teams, Main Window". So at least I can exclude this one.
Here is the best solution I have come to.
But it requires the user to confirm which window is the current meeting window (if not obvious).
The code can be found in this Gist: https://gist.github.com/tdalon/87590637e43479c90f355be90aff3842#file-teams_getmeetingwindow-ahk
Here is another solution (my preferred one) based on UIAutomation library - see https://tdalon.blogspot.com/2022/07/ahk-get-teams-meeting-win.html
Gist code https://gist.github.com/tdalon/5b3304559852d1d1942b7f1566de2a0c

AHK Script using PostClick and PostMessage

I'm trying to write a simple AHK script to type a few characters and make a few clicks at specific coordinates in a background window, but I can't seem to get it to work, and I'm not finding a lot of information on how to properly use PostClick.
I was able to get this to work using Click when the window is active. Also tried using ControlClick, which seemed to work, except the click was happening on the location where the mouse was rather than the coordinates provided (and also only when the window was activated again).
Can I please have some help / advice on how to get this to work?
Here's my current script:
DetectHiddenWindows On
S:: ;Character to start the loop
pid = 19164 ;Application PID
ControlGet, clickVar, Hwnd , , ahk_pid %pid% ;Specify control for which program
BreakLoop = 0
Loop, 3 {
if (BreakLoop = 1)
break
Sleep 1000
PostClick(clickVar,1055,525)
{
ControlSend,, 3, ahk_pid %pid%
lParam := x & 0xFFFF | (y & 0xFFFF) << 16
PostMessage, 0x201, , %lParam%, , ahk_pid %pid% ;WM_LBUTTONDOWN
PostMessage, 0x202, , %lParam%, , ahk_pid %pid% ;WM_LBUTTONUP
}
Sleep 1500
}
E::
BreakLoop = 1
return
Thanks ahead of time for the help.
I am going to assume you are attempting to use this function.
I am unsure how this function works, but I think what you want is something like:
DetectHiddenWindows On
S:: ;Character to start the loop
pid = 19164 ;Application PID
ControlGet, clickVar, Hwnd , , ahk_pid %pid% ;Specify control for which program
WinGetTitle, clickTitle, ahk_pid %pid%
WinGetClass, clickClass, ahk_pid %pid%
BreakLoop = 0
Loop, 3
{
if (BreakLoop = 1)
break
Sleep 1000
PostClick(1055,525,clickClass, clickTitle)
ControlSend,, 3, ahk_pid %pid%
Sleep 1500
}
E::
BreakLoop = 1
return
PostClick(x, y, class, title)
{
lParam := x & 0xFFFF | (y & 0xFFFF) << 16
PostMessage, 0x201, 1, %lParam%, %class%, %title% ;WM_LBUTTONDOWN
PostMessage, 0x202, 0, %lParam%, %class%, %title% ;WM_LBUTTONUP
}
You need to place the function somewhere in the same file or at least accessible by the current file. You can do #include <script name here>.ahk at the top of your file and place that function as a new file in the same directory if you want.
The function you are trying to use takes in an x and a y for where to click in that window. Then it also takes in a class and title in order to know which window to actually use. Hope this works or helps you in some way.

Autohotkey: Activate foremost of X monitor

How do I activate the foremost window in a given monitor? suppose I have two monitors, one with an editor, and one with different apps, such as chrome and slack. I want to bind a key that will activate the foremost window in monitor two, be it slack or chrome, and one for the editor, for easy manuvering.
The foremost window in a given monitor is the currently active window
or (if the currently active window is on the other monitor) the last active window of this monitor.
; activate the editor:
F1::
WinActivate, ahk_exe notepad.exe ; replace notepad with the ahk_exe of the editor
return
; activate the last active window in the right monitor:
F2::
WinGetPos, X,,,, A
If (X > 1920) ; replace 1920 with the width of the left monitor
return ; do nothing
; otherwise:
WinGet, id, list
Loop, %id%
{
this_ID := id%A_Index%
WinGet, exStyle, exStyle, ahk_id %this_ID%
If !(exStyle & 0x100)
continue
WinGetTitle, title, ahk_id %this_ID%
If (title = "")
continue
WinGetPos, X,,,, ahk_id %this_ID%
If (X > 1920) ; replace 1920 with the width of the left monitor
{
WinActivate, ahk_id %this_ID%
break
}
}
return

AHK key remapping alt tab

My goal is to make my mouse extra button act as alt tab so I could scroll through my tabs without using the keyboard.
XButton1::Alt
LButton::
If (GetKeyState("XButton1", "P"))
Send {TAB down}
LButton Up::
If (GetKeyState("XButton1", "P"))
Send {TAB up}
What I was hoping for this to do was when I am holding XButton1(the back button on my mouse) I could click and it would act as a tab and only while I am holding XButton1 otherwise it my click would act as a click
Try this:
XButton1::Send {XButton1} ; If you remove this line XButton1 loses its original/native function
; Hold down XButton1 and press LButton to navigate the alt-tab menu:
XButton1 & LButton::AltTab ; XButton1 becomes a prefix key
https://autohotkey.com/docs/Hotkeys.htm#combo
https://autohotkey.com/docs/Hotkeys.htm#AltTabDetail
; AltTab-replacement for Windows 8:
XButton1 & LButton::
list = ""
WinGet, id, list
Loop, %id%
{
this_ID := id%A_Index%
WinGet, exStyle, exStyle, ahk_id %this_ID%
If !(exStyle & 0x100)
continue
IfWinActive, ahk_id %this_ID%
continue
WinGetTitle, title, ahk_id %this_ID%
If (title = "")
continue
WinActivate, ahk_id %this_ID%
break
}
return
; AltTabMenu-replacement for Windows 8:
XButton1 & RButton::
list = ""
Menu, windows, Add
Menu, windows, deleteAll
WinGet, id, list
Loop, %id%
{
this_ID := id%A_Index%
WinGet, exStyle, exStyle, ahk_id %this_ID%
If !(exStyle & 0x100)
continue
WinGetTitle, title, ahk_id %this_ID%
If (title = "")
continue
WinGetClass, class, ahk_id %this_ID%
If (class = "")
continue
If (class = "ApplicationFrameWindow")
continue
Menu, windows, Add, %title%%A_Tab%ahk_class %class%, ActivateWindow
WinGet, Path, ProcessPath, ahk_id %this_ID%
Menu, windows, Icon, %title%%A_Tab%ahk_class %class%, %Path%,, 0
}
Menu, windows, Show
return
ActivateWindow:
WinActivate, %A_ThisMenuItem%
return
XButton1::Send {XButton1}

Autohotkey and Windows 10: How to get current explorer path

I use autohotkey version: 1.0.48.05 (because I stick with activeaid).
The script to read the current path is as follows (and worked until Win 7).
; Get full path from open Explorer window
WinGetText, FullPath, A
; Clean up result
StringReplace, FullPath, FullPath, `r, , all
FullPath := RegExReplace(FullPath, "^.*`nAddress: ([^`n]+)`n.*$", "$1")
How I suspect that while switching to Win10 it seems that I also switched the language.
If I MsgBox out the %FullPath% before cleaning with
WinGetText, FullPath, A
MsgBox %FullPath%
I see amongst other strings (obvoíously separated by CR):
Adresse: V:\Vertrieb\Prospects\MyFile
so how do I need to adjust the regexp to extract that very string!
Best regards
Hannes
#IfWinActive, ahk_class CabinetWClass ; explorer
F1:: MsgBox, % GetActiveExplorerPath()
; or
F2::
ActiveExplorerPath := GetActiveExplorerPath()
MsgBox, % ActiveExplorerPath
return
#IfWinActive
GetActiveExplorerPath() {
; https://www.autohotkey.com/boards/viewtopic.php?f=6&t=69925
explorerHwnd := WinActive("ahk_class CabinetWClass")
if (explorerHwnd)
{
for window in ComObjCreate("Shell.Application").Windows
{
if (window.hwnd==explorerHwnd)
return window.Document.Folder.Self.Path
}
}
}
Try:
f1::MsgBox % Explorer_GetSelection()
Explorer_GetSelection(hwnd="") {
WinGet, process, processName, % "ahk_id" hwnd := hwnd? hwnd:WinExist("A")
WinGetClass class, ahk_id %hwnd%
if (process = "explorer.exe")
if (class ~= "(Cabinet|Explore)WClass") {
for window in ComObjCreate("Shell.Application").Windows
if (window.hwnd==hwnd)
path := window.Document.FocusedItem.path
SplitPath, path,,dir
}
return dir
}
It takes me so much time to find the best solution (for me).
Maybe it will work for you as well.
ControlClick, ToolbarWindow323, A
ControlGetText, path, Edit1, A
Msgbox, %path%