gpt4 book ai didi

autohotkey - 在自动热键中检测事件的 Chrome 配置文件

转载 作者:行者123 更新时间:2023-12-02 02:48:49 28 4
gpt4 key购买 nike

我有 2 个 google Chrome 配置文件,1 个用于工作,1 个用于个人使用。有时我会同时打开这两个配置文件,并且我希望我的 ahk 脚本仅在特定配置文件窗口处于焦点时运行。所以我查找了一些示例,并制作了如下测试脚本:

IfWinActive, ahk_exe chrome.exe 
{
sPat = chrome.exe.*--profile-directory="Profile 4"
for process in ComObjGet("winmgmts:").ExecQuery("Select * from Win32_Process where Name = 'chrome.exe'")
{
If RegExMatch(process.Commandline,sPat)
{
MouseMove, 500, 500
Return
}
Else
{
Return
}
}
}
Else
{
Return
}

但这行不通。该脚本无法检测到配置文件,而是直接跳至第 13 行。我哪里做错了?有什么办法可以解决吗?

最佳答案

请检查一下它是否适合您

/**
* Description : AutoHotKey script bring specific Chrome Profile windows to the front.
* : While Chrome is active press Ctrl+1 ... Ctrl+5 to activate another profile.
* Tested with : Chrome v84
* Freelancer : Art G. - https://www.upwork.com/freelancers/~017155e179702d4657
* Version : 2020-07-17
*/

#Warn
#NoEnv
#SingleInstance Force

SetBatchLines -1
SetTitleMatchMode 2

GroupAdd ChromeWindow, ahk_exe chrome.exe ahk_class Chrome_WidgetWin_1

#IfWinActive ahk_group ChromeWindow
^1:: ActivateProfile("Default")
^2:: ActivateProfile("Profile 2")
^3:: ActivateProfile("Profile 3")
^4:: ActivateProfile("Profile 4")
^5:: ActivateProfile("Profile 5")
#IfWinActive

ActivateProfile(profile) {
static profiles := {}, hwnds := {}

If (!profiles[profile]) {
FileRead preferences, % SubStr(A_AppData, 1, -8) "\Local\Google\Chrome\User Data\" profile "\Preferences"
profiles[profile] := {}

RegExMatch(preferences, "O)""name"":\s*""(.+?)""", match)
profiles[profile]["name"] := match[1]

RegExMatch(preferences, "O)""given_name"":\s*""(.+?)""", match)
profiles[profile]["given_name"] := match[1]
}

WinGet hwndList, List, ahk_group ChromeWindow
Loop % hwndList {
hwnd := hwndList%A_Index%
If (!hwnds[hwnd]) {
title := Acc_ObjectFromWindow(hwnd).accName
RegExMatch(title, "O)^.+Google Chrome . .*?([^(]+[^)]).?$", match)
hwnds[hwnd] := match[1]
}

If (hwnds[hwnd] == profiles[profile]["name"] || hwnds[hwnd] == profiles[profile]["given_name"]) {
WinActivate ahk_id %hwnd%

For hwnd In hwnds {
If (!WinExist("ahk_id" hwnd))
hwnds.Delete(hwnd)
}

Return
}
}

Run chrome.exe --profile-directory="%profile%"
}

Acc_Init() {
static h := DllCall("LoadLibrary", Str,"oleacc", Ptr)
}

Acc_ObjectFromWindow(hwnd, objectId := 0) {
static OBJID_NATIVEOM := 0xFFFFFFF0

objectId &= 0xFFFFFFFF
If (objectId == OBJID_NATIVEOM)
riid := -VarSetCapacity(IID, 16) + NumPut(0x46000000000000C0, NumPut(0x0000000000020400, IID, "Int64"), "Int64")
Else
riid := -VarSetCapacity(IID, 16) + NumPut(0x719B3800AA000C81, NumPut(0x11CF3C3D618736E0, IID, "Int64"), "Int64")

If (DllCall("oleacc\AccessibleObjectFromWindow", Ptr,hwnd, UInt,objectId, Ptr,riid, PtrP,pacc:=0) == 0)
Return ComObject(9, pacc, 1), ObjAddRef(pacc)
}

关于autohotkey - 在自动热键中检测事件的 Chrome 配置文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/62401030/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com