Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to remap a key using AHK to open and close Google Chrome

I am new to AHK and been trying to fidget around with it for quite some time, what I need to do is open a specific profile of Google Chrome when a key is pressed and if it's open close it when the same key is pressed. I tried many things but can't quite figure out how to do it, this is what I have right now.

PgDn::
    Process, Exist, chrome.exe
If ErrorLevel <> 0
    Process, Close, chrome.exe
Else    
    Run, "C:\Program Files (x86)\Google\Chrome\Application\chrome.exe" --profile-directory="Profile 1"
return

This opens up the chrome to a profile I want but when I close press the button again it closes any and every chrome window open. I understand that's because I close the chrome.exe process, I cannot figure out how to close that specific profile.

Ultimately what I want to do is when the Page Down key is pressed

If Chrome Profile 1 is not opened, open it.
If Chrome Profile 1 is minimized, maximize it.
and if Chrome Profile 1 is opened and maximized, close it.

I would really appreciate if someone could assist with this.

like image 915
Adam Johns Avatar asked Nov 21 '25 16:11

Adam Johns


1 Answers

AHK's Run command has a parameter named: OutputVarPID.

you can use this to store the process id of the started chrome instance in a variable, which you can then pass to your Exit command.

like image 98
Cerbrus Avatar answered Nov 24 '25 04:11

Cerbrus



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!