More elegant solution than ImageSearch to change mouse profile?

Ask gaming related questions (AHK v1.1 and older)
SmithyZoomZoom
Posts: 111
Joined: 23 Aug 2019, 23:32

More elegant solution than ImageSearch to change mouse profile?

02 May 2020, 21:46

Hello:

Originally, I was contemplating using an image search to change my mouse profile but I am wondering if there is a way to automate the process in a manner that bypasses the mouse altogether? Here is a clip of what I am trying to automate. I know the little clip place back at a snail's pace. It takes me 40 seconds to do it because of fine motor skill impairment, which is why I am interested in creating some kind of macro:
https://imgur.com/a/Uvhm7C2

Thank you for any help. I can start gathering tiny screenshots of places to click in the Logitech software, if that is indeed the best way. You may see within the software something called a profile cycling button. Unfortunately, I do not think it will help in my case because I'm trying to change something called the persistent profile, Which is different from the standard profile set.

I appreciate your time.
BoBo
Posts: 6564
Joined: 13 May 2014, 17:15

Re: More elegant solution than ImageSearch to change mouse profile?

03 May 2020, 04:00

I'd go with a keyboard choreography of tabs/up/downs/etc that is often more reliable than mouse movements and ImageSearch MouseMove (re)positioning attempts. Please check if you can move through that configuration panel (and selecting options) using the keyboard alone. Afterward, creating a script for this shouldn't be a problem. Good luck :)
User avatar
Cuadrix
Posts: 236
Joined: 07 May 2017, 08:26

Re: More elegant solution than ImageSearch to change mouse profile?

03 May 2020, 04:26

Maybe the program has a dedicated folder for storing profiles somewhere?
If so, maybe just some simple file write and rename magic would do the trick.
SmithyZoomZoom
Posts: 111
Joined: 23 Aug 2019, 23:32

Re: More elegant solution than ImageSearch to change mouse profile?

04 May 2020, 09:53

Cuadrix wrote:
03 May 2020, 04:26
Maybe the program has a dedicated folder for storing profiles somewhere?
If so, maybe just some simple file write and rename magic would do the trick.
Thanks, everyone!

I found the settings file. I mean, I have No idea what to do with it. But I found it. This is for Logitech gaming software:

Code: Select all

{
  "Firmware" : 
  {
    "G305" : 
    {
      "Last_Check" : "2020-04-10"
    }
  },
  "analytics" : 
  {
    "enabled" : false
  },
  "current_profile_id" : "{09D92D75-3C8C-4723-B06C-4090BCB899C0}",
  "gameApplets" : 
  {
    "C:|Program Files|Logitech Gaming Software|ArxApplets|Assetto Corsa|AssettoCorsaArxApplet.exe" : 
    {
      "id" : "scan_from_known_folder",
      "launch" : 
      {
        "profile_associated_but_game_not_found" : true,
        "profile_guid" : "{9E6D8C2F-0983-4008-8EE3-EC5554C88CAF}",
        "type" : "never"
      },
      "name" : "Assetto Corsa",
      "support" : 
      {
        "arx" : 
        {
          "enabled" : true,
          "support" : true
        },
        "led" : 
        {
          "enabled" : true,
          "support" : true
        }
      }
    },
    "C:|Program Files|Logitech Gaming Software|ArxApplets|Audio Visualizer|Audio_Visualizer_Arx_Applet.exe" : 
    {
      "id" : "scan_from_known_folder",
      "launch" : 
      {
        "type" : "never"
      },
      "name" : "Audio Visualizer",
      "support" : 
      {
        "arx" : 
        {
          "enabled" : false,
          "support" : false
        },
        "led" : 
        {
          "enabled" : true,
          "support" : true
        }
      }
    },
    "C:|Program Files|Logitech Gaming Software|ArxApplets|Counter Strike - GO|CS_GO_Arx_Applet.exe" : 
    {
      "id" : "scan_from_known_folder",
      "launch" : 
      {
        "profile_associated_but_game_not_found" : true,
        "profile_guid" : "{A2606DAA-7B0C-4CA6-B203-2E86E5BE3325}",
        "type" : "never"
      },
      "name" : "Counter Strike - GO",
      "support" : 
      {
        "arx" : 
        {
          "enabled" : true,
          "support" : true
        },
        "led" : 
        {
          "enabled" : true,
          "support" : true
        }
      }
    },
    "C:|Program Files|Logitech Gaming Software|ArxApplets|Discord|logitechg_discord.exe" : 
    {
      "id" : "scan_from_known_folder",
      "launch" : 
      {
        "type" : "startup"
      },
      "name" : "Discord",
      "support" : 
      {
        "arx" : 
        {
          "enabled" : false,
          "support" : false
        },
        "led" : 
        {
          "enabled" : true,
          "support" : true
        }
      }
    },
    "C:|Program Files|Logitech Gaming Software|ArxApplets|Dota 2|Dota2ArxApplet.exe" : 
    {
      "id" : "scan_from_known_folder",
      "launch" : 
      {
        "profile_associated_but_game_not_found" : true,
        "profile_guid" : "{306FB93B-96A8-43EB-9B5A-352D93EEE712}",
        "type" : "never"
      },
      "name" : "Dota 2",
      "support" : 
      {
        "arx" : 
        {
          "enabled" : true,
          "support" : true
        },
        "led" : 
        {
          "enabled" : true,
          "support" : true
        }
      }
    },
    "C:|Program Files|Logitech Gaming Software|ArxApplets|Screen Sampler|ScreenSampler.exe" : 
    {
      "id" : "scan_from_known_folder",
      "launch" : 
      {
        "type" : "never"
      },
      "name" : "Screen Sampler",
      "support" : 
      {
        "arx" : 
        {
          "enabled" : false,
          "support" : false
        },
        "led" : 
        {
          "enabled" : false,
          "support" : true
        }
      }
    }
  },
  "inputTracker" : 
  {
    "spectrum" : 2
  },
  "lcd" : 
  {
    "applets" : 
    {
      "c86a" : 
      {
        "appPath" : "C:/Program Files/Logitech Gaming Software/LCore.exe",
        "autostartable" : false,
        "format" : 0,
        "iconPath" : "",
        "name" : "G-Series Profile Selector"
      },
      "c872" : 
      {
        "appPath" : "C:/Program Files/Logitech Gaming Software/LCore.exe",
        "autostartable" : false,
        "format" : 0,
        "iconPath" : "",
        "name" : "Logitech Gaming Profiler"
      },
      "d9e3" : 
      {
        "appPath" : "C:/Program Files/Logitech Gaming Software/LCore.exe",
        "autostartable" : false,
        "format" : 1,
        "iconPath" : "",
        "name" : "G-Series Profile Selector"
      },
      "d9fb" : 
      {
        "appPath" : "C:/Program Files/Logitech Gaming Software/LCore.exe",
        "autostartable" : false,
        "format" : 1,
        "iconPath" : "",
        "name" : "Logitech Gaming Profiler"
      }
    }
  },
  "mainapp" : 
  {
    "autostart" : true
  },
  "mainwindow" : 
  {
    "ScanForGames" : true,
    "dynamicImageDownload" : true,
    "enableAppletDeviceView" : true,
    "enableLEDSDK" : true,
    "hasAppletMgrBeenSeen" : true,
    "lastUsedDevice" : "Logitech.Gaming.Mouse.G305",
    "useEnhancedGraphics" : false
  },
  "mobile" : 
  {
    "authentication" : null,
    "delay" : 
    {
      "enabled" : false
    },
    "service" : 
    {
      "enabled" : true,
      "no-new-paring-allowed" : false
    },
    "service_guid" : "{7f02a60d-d51b-4c40-9459-7c586d8d3476}"
  },
  "notification" : 
  {
    "showBatteryWarningOnTaskbar" : true,
    "showDpiChangeToastNotify" : true,
    "showProfileChangeToastNotify" : true
  },
  "pointer" : 
  {
    "Logitech.Gaming.Mouse.G305" : 
    {
      "currentDPIValue" : 
      [
        800,
        800
      ],
      "dpi" : 
      {
        "defaultIndex" : 1,
        "shiftIndex" : 0,
        "syncXY" : true,
        "values" : 
        [
          {
            "enabled" : true,
            "x" : 400,
            "y" : 400
          },
          {
            "enabled" : true,
            "x" : 800,
            "y" : 800
          },
          {
            "enabled" : true,
            "x" : 1600,
            "y" : 1600
          },
          {
            "enabled" : true,
            "x" : 3200,
            "y" : 3200
          }
        ]
      }
      "hardwareMode" : false,
      "powerMode" : 3,
      "reportRate" : 250
    },
    "hasAcceleration" : false
  },
  "profiler" : 
  {
    "autoScannedForGames" : true,
    "defaultProfile" : "{09D92D75-3C8C-4723-B06C-4090BCB899C0}",
    "enableQuickMacroDelays" : false,
    "joystickMouseSpeed" : 127,
    "lastProfile" : "{09D92D75-3C8C-4723-B06C-4090BCB899C0}",
    "persistentProfile" : "{09D92D75-3C8C-4723-B06C-4090BCB899C0}",
    "profileCyclingCmd" : 0,
    "recordMultiKeyMacroDelays" : false,
    "showMacroActivationOnLCD" : false,
    "showProfileActivationOnLCD" : true,
    "showQuickMacrosOnLCD" : true,
    "sp" : 
    {
      "hasMigrated" : true
    }
  },
  "splashscreen" : 
  {
    "G560_first" : true
  },
  "sync_effect_settings" : 
  {
    "settings" : null
  }
}
SmithyZoomZoom
Posts: 111
Joined: 23 Aug 2019, 23:32

Re: More elegant solution than ImageSearch to change mouse profile?

06 May 2020, 21:50

I figured out more things today.
In order to get it to do what I want, I have to change the persistent profile line in the earlier document I posted to this:

"persistentProfile" : "{5FAEA13C-DF17-44E4-8714-A0E9BF212D4E}",

Any idea what I would have to do to get AutoHotkey to rewrite the line and save it?
SmithyZoomZoom
Posts: 111
Joined: 23 Aug 2019, 23:32

Re: More elegant solution than ImageSearch to change mouse profile?

07 May 2020, 20:41

I found a discussion with possible ways to rewrite the configuration file but I'm a little nervous because I don't want to accidentally mess up my mouse:
https://autohotkey.com/board/topic/52476-how-to-write-into-a-text-file/
User avatar
Cuadrix
Posts: 236
Joined: 07 May 2017, 08:26

Re: More elegant solution than ImageSearch to change mouse profile?

08 May 2020, 07:21

First backup the file just in case. For example, copy the settings file to the desktop or something.
This should work, not tested:

Code: Select all

MySettings = C:\My Documents\My Settings.txt ; Location of settings file
OldProfile = "persistentProfile" : "{09D92D75-3C8C-4723-B06C-4090BCB899C0}"
NewProfile = "persistentProfile" : "{5FAEA13C-DF17-44E4-8714-A0E9BF212D4E}"

; First check if file exists
If (!FileExist(MySettings)) {
	MsgBox, File doesn't exist.
	ExitApp
}
; Read the file contents into a variable
FileRead, FileContent, %MySettings%

; Replace the profile in the old file contents, then assign modified content to a variable
NewContent := StrReplace(FileContent, OldProfile, NewProfile)

; Delete the settings file for recreation
FileDelete, %MySettings%

; Create a new settings file with modified contents
FileAppend, %NewContent%, %MySettings%
SmithyZoomZoom
Posts: 111
Joined: 23 Aug 2019, 23:32

Re: More elegant solution than ImageSearch to change mouse profile?

08 May 2020, 09:13

That works. So long as I close out the mouse software, run the autohotkey scrript, and then reopen the mouse profile software.

Is there a way to read the settings file, and if it contains anything different from the new profile line, rewrite it with the new profile variable?

Thank you.
User avatar
Cuadrix
Posts: 236
Joined: 07 May 2017, 08:26

Re: More elegant solution than ImageSearch to change mouse profile?

08 May 2020, 13:05

It's possible in many ways. Simplest way in my opinion is to use a parsing loop, not tested:

Code: Select all

MySettings = C:\My Documents\My Settings.txt ; Location of settings file
NewProfile = "persistentProfile" : "{5FAEA13C-DF17-44E4-8714-A0E9BF212D4E}"

; First check if the settings file exists
If (!FileExist(MySettings)) {
	MsgBox, File doesn't exist.
	ExitApp
}

; Read the file contents into a variable
FileRead, FileContent, %MySettings%

Loop, Parse, FileContent, `n, `r
{
	; A_LoopField contains the current line of the loop
	; If the current line contains "persistentProfile", then proceed to the block below
	if (InStr(A_LoopField, "persistentProfile")) {
	
		; A_LoopField contains "persistentProfile" so it's the current profile
		; If the profile is NOT equal to the value of NewProfile variable, then proceed to the block below
		if (A_LoopField != NewProfile) {
			
			; Replace the profile in the old file contents, then assign modified content to a variable
			NewContent := StrReplace(FileContent, A_LoopField, NewProfile)
			
			; Delete the settings file for recreation
			FileDelete, %MySettings%
			
			; Create a new settings file with modified contents
			FileAppend, %NewContent%, %MySettings%
		}
	}
}

The above should replace the line if NewProfile doesn't exist and do nothing if it already does exist.
The opening and closing of your mouse software can be automated as well, though you might have to run the script as administrator; not tested:

Code: Select all

MySettings = C:\My Documents\My Settings.txt ; Location of settings file
NewProfile = "persistentProfile" : "{5FAEA13C-DF17-44E4-8714-A0E9BF212D4E}"

SoftwareProcessName = process.exe ; Process name for closing the process -> Check taskmanager
SoftwareExecutable = C:\Program Files\Mouse\Sofware.exe ; .exe file location

; First check if settings file exists
If (!FileExist(MySettings)) {
	MsgBox, File doesn't exist.
	ExitApp
}

; Read the file contents into a variable
FileRead, FileContent, %MySettings%

Loop, Parse, FileContent, `n, `r
{
	; A_LoopField contains the current line of the loop
	; If the current line contains "persistentProfile", then proceed to the block below
	if (InStr(A_LoopField, "persistentProfile")) {
	
		; A_LoopField contains "persistentProfile" so it's the current profile
		; If the profile is NOT equal to the value of NewProfile variable, then proceed to the block below
		if (A_LoopField != NewProfile) {
			
			; Replace the profile in the old file contents, then assign modified content to a variable
			NewContent := StrReplace(FileContent, A_LoopField, NewProfile)
			
			; Better to close the software before writing
			; Check if software is open, and close if it is
			Process, Exist, %SoftwareProcessName%
			if (ErrorLevel)
				Process, Close, %SoftwareProcessName%
			
			; Delete the settings file for recreation
			FileDelete, %MySettings%
			
			; Create a new settings file with modified contents
			FileAppend, %NewContent%, %MySettings%
			
			; Reopen sofware
			Run, %SoftwareExecutable%
		}
	}
}
SmithyZoomZoom
Posts: 111
Joined: 23 Aug 2019, 23:32

Re: More elegant solution than ImageSearch to change mouse profile?

08 May 2020, 21:37

Thank you! Your code 99% worked like a charm. I've been trying to get the last 1% to work for three hours and it's all the more frustrating because it should be really basic stuff that even I know how to do. So, your code closes the mouse software, writes to the configuration file, and reopens the mouse software. So far so good. The problem comes when the software reopens. There's this annoying splash screen that happens on the first run after the configuration file has initially been rewritten. So all I have been trying to do for the last three hours is to close and reopen the program:

Code: Select all

MySettings = C:\Users\2015 Win10\AppData\Local\Logitech\Logitech Gaming Software\settings.json ; Location of settings file
NewProfile = "persistentProfile" : "{5FAEA13C-DF17-44E4-8714-A0E9BF212D4E}"

SoftwareProcessName = LCore.exe ; Process name for closing the process -> Check taskmanager
SoftwareExecutable = C:\Program Files\Logitech Gaming Software\LCore.exe ; .exe file location

; First check if settings file exists
If (!FileExist(MySettings)) {
	MsgBox, File doesn't exist.
	ExitApp
}

; Read the file contents into a variable
FileRead, FileContent, %MySettings%

Loop, Parse, FileContent, `n, `r
{
	; A_LoopField contains the current line of the loop
	; If the current line contains "persistentProfile", then proceed to the block below
	if (InStr(A_LoopField, "persistentProfile")) {
	
		; A_LoopField contains "persistentProfile" so it's the current profile
		; If the profile is NOT equal to the value of NewProfile variable, then proceed to the block below
		if (A_LoopField != NewProfile) {
			
			; Replace the profile in the old file contents, then assign modified content to a variable
			NewContent := StrReplace(FileContent, A_LoopField, NewProfile)
			
			; Better to close the software before writing
			; Check if software is open, and close if it is
			Process, Exist, %SoftwareProcessName%
			if (ErrorLevel)
				Process, Close, %SoftwareProcessName%
			
			; Delete the settings file for recreation
			FileDelete, %MySettings%
			
			; Create a new settings file with modified contents
			FileAppend, %NewContent%, %MySettings%
			
			; Reopen sofware
			Run, %SoftwareExecutable%
			RunWait mouse_close.bat ; Basic taskkill line to Close the mouse program because your more elegant Process, Close, %SoftwareProcessName% confusingly would not work.
			RunWait, %SoftwareExecutable% ; This line does not appear to work. The mouse software does not seem to run. I also used a regular Run command to no avail.
			
			
		
			
			
			
			
		}
	}
}

ExitApp
Thank you for any assistance you might choose to offer.
User avatar
Cuadrix
Posts: 236
Joined: 07 May 2017, 08:26

Re: More elegant solution than ImageSearch to change mouse profile?

09 May 2020, 08:57

You are attempting to close and reopen the script a second time when it's not necessary. Remove these:

Code: Select all

RunWait mouse_close.bat ; Basic taskkill line to Close the mouse program because your more elegant Process, Close, %SoftwareProcessName% confusingly would not work.
RunWait, %SoftwareExecutable% ; This line does not appear to work. The mouse software does not seem to run. I also used a regular Run command to no avail.

This already reopens the software, so you don't need to do it twice with the lines above. It closes the software, writes to the settings file, then reopens the software. When the sofware reopens, it will read from our modified settings file automatically:

Code: Select all

MySettings = C:\Users\2015 Win10\AppData\Local\Logitech\Logitech Gaming Software\settings.json ; Location of settings file
NewProfile = "persistentProfile" : "{5FAEA13C-DF17-44E4-8714-A0E9BF212D4E}"

SoftwareProcessName = LCore.exe ; Process name for closing the process -> Check taskmanager
SoftwareExecutable = C:\Program Files\Logitech Gaming Software\LCore.exe ; .exe file location

; First check if settings file exists
if (!FileExist(MySettings)) {
	MsgBox, File doesn't exist.
	ExitApp
}

; Read the file contents into a variable
FileRead, FileContent, %MySettings%

Loop, Parse, FileContent, `n, `r
{
	; A_LoopField contains the current line of the loop
	; If the current line contains "persistentProfile", then proceed to the block below
	if (InStr(A_LoopField, "persistentProfile")) {
	
		; A_LoopField contains "persistentProfile" so it's the current profile
		; If the profile is NOT equal to the value of NewProfile variable, then proceed to the block below
		if (A_LoopField != NewProfile) {
			
			; Replace the profile in the old file contents, then assign modified content to a variable
			NewContent := StrReplace(FileContent, A_LoopField, NewProfile)
			
			; Better to close the software before writing
			; Check if software is open, and close if it is
			Process, Exist, %SoftwareProcessName%
			if (ErrorLevel)
				Process, Close, %SoftwareProcessName%
			
			; Delete the settings file for recreation
			FileDelete, %MySettings%
			
			; Create a new settings file with modified contents
			FileAppend, %NewContent%, %MySettings%
			
			; Reopen sofware
			Run, %SoftwareExecutable%
			
			; There is no point in looping through the rest of the lines, so exit the script now
			ExitApp
		}
	}
}

If the above doesn't work, perhaps due to the software automatically writing to the settings file before closing, then maybe rearranging the script to reopen it ONLY after writing to the file would work:

Code: Select all

MySettings = C:\Users\2015 Win10\AppData\Local\Logitech\Logitech Gaming Software\settings.json ; Location of settings file
NewProfile = "persistentProfile" : "{5FAEA13C-DF17-44E4-8714-A0E9BF212D4E}"

SoftwareProcessName = LCore.exe ; Process name for closing the process -> Check taskmanager
SoftwareExecutable = C:\Program Files\Logitech Gaming Software\LCore.exe ; .exe file location

; First check if settings file exists
if (!FileExist(MySettings)) {
	MsgBox, File doesn't exist.
	ExitApp
}

; Read the file contents into a variable
FileRead, FileContent, %MySettings%

Loop, Parse, FileContent, `n, `r
{
	; A_LoopField contains the current line of the loop
	; If the current line contains "persistentProfile", then proceed to the block below
	if (InStr(A_LoopField, "persistentProfile")) {
	
		; A_LoopField contains "persistentProfile" so it's the current profile
		; If the profile is NOT equal to the value of NewProfile variable, then proceed to the block below
		if (A_LoopField != NewProfile) {
			
			; Replace the profile in the old file contents, then assign modified content to a variable
			NewContent := StrReplace(FileContent, A_LoopField, NewProfile)
			
			; Delete the settings file for recreation
			FileDelete, %MySettings%
			
			; Create a new settings file with modified contents
			FileAppend, %NewContent%, %MySettings%
			
			; Check if software is open, and close if it is
			Process, Exist, %SoftwareProcessName%
			if (ErrorLevel)
				Process, Close, %SoftwareProcessName%
				
			; Reopen sofware
			Run, %SoftwareExecutable%
			
			; There is no point in looping through the rest of the lines, so exit the script now
			ExitApp
		}
	}
}

You can also sleep a couple seconds before reopening the software, e.g. Sleep, 2000, to give it a little time to do it's thing.
SmithyZoomZoom
Posts: 111
Joined: 23 Aug 2019, 23:32

Re: More elegant solution than ImageSearch to change mouse profile?

11 May 2020, 08:51

The problem still persists in but thank you for kindly for continuing your efforts!

Here is the code I used, from your example:

Code: Select all

MySettings = C:\Users\2015 Win10\AppData\Local\Logitech\Logitech Gaming Software\settings.json ; Location of settings file
NewProfile = "persistentProfile" : "{5FAEA13C-DF17-44E4-8714-A0E9BF212D4E}"

SoftwareProcessName = LCore.exe ; Process name for closing the process -> Check taskmanager
SoftwareExecutable = C:\Program Files\Logitech Gaming Software\LCore.exe ; .exe file location

; First check if settings file exists
if (!FileExist(MySettings)) {
	MsgBox, File doesn't exist.
	ExitApp
}

; Read the file contents into a variable
FileRead, FileContent, %MySettings%

Loop, Parse, FileContent, `n, `r
{
	; A_LoopField contains the current line of the loop
	; If the current line contains "persistentProfile", then proceed to the block below
	if (InStr(A_LoopField, "persistentProfile")) {
	
		; A_LoopField contains "persistentProfile" so it's the current profile
		; If the profile is NOT equal to the value of NewProfile variable, then proceed to the block below
		if (A_LoopField != NewProfile) {
			
			; Replace the profile in the old file contents, then assign modified content to a variable
			NewContent := StrReplace(FileContent, A_LoopField, NewProfile)
			
			; Delete the settings file for recreation
			FileDelete, %MySettings%
			
			; Create a new settings file with modified contents
			FileAppend, %NewContent%, %MySettings%
			
			; Check if software is open, and close if it is
			Process, Exist, %SoftwareProcessName%
			if (ErrorLevel)
				Process, Close, %SoftwareProcessName%
				
			; Reopen sofware
			Sleep, 2000
			Run, %SoftwareExecutable%
			
			; There is no point in looping through the rest of the lines, so exit the script now
			ExitApp
		}
	}
}
When the mouse program loads, this is what it looks like:
https://imgur.com/a/cxKrJbv

After I click the X in the upper right corner, the main mouse program screen appears:
https://imgur.com/a/UqSxjsj

Clicking with the mouse manually, if I were to exit out of the mouse software and reopen it, it takes me directly to the main mouse screen as shown in the UqSxjsj link.

However, whenever I run the script, when the software reopens it looks like the cxKrJbv link. I am hoping to be able to get it to load like the preferred UqSxjsj link, instead of having to click the X after every time I run the profile swapper.

Any continued advice be awesome! Thank you so much for your time.
User avatar
Cuadrix
Posts: 236
Joined: 07 May 2017, 08:26

Re: More elegant solution than ImageSearch to change mouse profile?

11 May 2020, 10:33

The reason it the splash screen comes is because the script completely closes the program whereas when you manually click on the x it only closes the main window, meaning that you can still probably see a small logitech icon in the system tray on the right side of the screen near the date/time.

I'm sceptical of whether the software will actually begin using the new profile if you only close and reopen the main window, but you can try this anyways:

Code: Select all

MySettings = C:\Users\2015 Win10\AppData\Local\Logitech\Logitech Gaming Software\settings.json ; Location of settings file
NewProfile = "persistentProfile" : "{5FAEA13C-DF17-44E4-8714-A0E9BF212D4E}"

SoftwareExecutable = C:\Program Files\Logitech Gaming Software\LCore.exe ; .exe file location
SoftwareWindowName = Logitech Gaming Software ; Check from Autohotkey's Window Spy to confirm

; First check if settings file exists
if (!FileExist(MySettings)) {
	MsgBox, File doesn't exist.
	ExitApp
}

; Read the file contents into a variable
FileRead, FileContent, %MySettings%

Loop, Parse, FileContent, `n, `r
{
	; A_LoopField contains the current line of the loop
	; If the current line contains "persistentProfile", then proceed to the block below
	if (InStr(A_LoopField, "persistentProfile")) {
	
		; A_LoopField contains "persistentProfile" so it's the current profile
		; If the profile is NOT equal to the value of NewProfile variable, then proceed to the block below
		if (A_LoopField != NewProfile) {
			
			; Replace the profile in the old file contents, then assign modified content to a variable
			NewContent := StrReplace(FileContent, A_LoopField, NewProfile)
			
			; Close the main window before writing
			; Check if the main window is open, and close if it is
			if (WinExist(SoftwareWindowName))
				WinClose, %SoftwareWindowName%
			
			; Delete the settings file for recreation
			FileDelete, %MySettings%
			
			; Create a new settings file with modified contents
			FileAppend, %NewContent%, %MySettings%
			
			; Rerun the software executable to reopen main window (?)
			Run, %SoftwareExecutable%
			
			; There is no point in looping through the rest of the lines, so exit the script now
			ExitApp
		}
	}
}

If you want to properly close and reopen the software instead, then you should only close the splash screen itself. To do that, you will first have to confirm whether the splashscreen (https://imgur.com/a/cxKrJbv) has the same name as the main window (https://imgur.com/a/UqSxjsj). To do that, you can use Autohotkey's Window Spy. Just type "Window Spy" in the windows start menu and it should appear.
Launch Window Spy, and put your mouse over the logitech software splash screen window so that Window Spy can read information from it.
We are after the the window name. It's in the first "box", e.g.;

Code: Select all

/*
 Window Title, Class and Process:             Follow Mouse [  ]
 --------------------------------------------------------------
| HERE                                                         |
| ahk_class...                                                 |
| ahk_exe...                                                   |
| ahk_pid...                                                   |
 --------------------------------------------------------------
*/

Though you don't have to do the above if you are satisfied with the script above it.
SmithyZoomZoom
Posts: 111
Joined: 23 Aug 2019, 23:32

Re: More elegant solution than ImageSearch to change mouse profile?

14 May 2020, 00:58

You were right! There seems to be a separate labeling in Windows Spy:


nonsplash screen window spy
Logitech Gaming Software
ahk_class Qt5QWindowIcon
ahk_exe LCore.exe
ahk_pid 18760

splash screen window spy
Logitech Gaming Software
ahk_class Qt5QWindowToolTipSaveBits
ahk_exe LCore.exe
ahk_pid 24372

I appreciate your understanding of my most recent delay replying and am sincerely grateful for your attempts to complete the script in the best way possible. Thank you!
User avatar
Cuadrix
Posts: 236
Joined: 07 May 2017, 08:26

Re: More elegant solution than ImageSearch to change mouse profile?

14 May 2020, 14:30

Since the splash and main windows have the same window name, try this:

Code: Select all

MySettings = C:\Users\2015 Win10\AppData\Local\Logitech\Logitech Gaming Software\settings.json ; Location of settings file
NewProfile = "persistentProfile" : "{5FAEA13C-DF17-44E4-8714-A0E9BF212D4E}"

SoftwareProcessName = LCore.exe ; Process name for closing the process -> Check taskmanager
SoftwareExecutable = C:\Program Files\Logitech Gaming Software\LCore.exe ; .exe file location
SoftwareWindowName = Logitech Gaming Software ; Check from Autohotkey's Window Spy to confirm

; First check if settings file exists
if (!FileExist(MySettings)) {
	MsgBox, File doesn't exist.
	ExitApp
}

; Read the file contents into a variable
FileRead, FileContent, %MySettings%

Loop, Parse, FileContent, `n, `r
{
	; A_LoopField contains the current line of the loop
	; If the current line contains "persistentProfile", then proceed to the block below
	if (InStr(A_LoopField, "persistentProfile")) {
	
		; A_LoopField contains "persistentProfile" so it's the current profile
		; If the profile is NOT equal to the value of NewProfile variable, then proceed to the block below
		if (A_LoopField != NewProfile) {
			
			; Replace the profile in the old file contents, then assign modified content to a variable
			NewContent := StrReplace(FileContent, A_LoopField, NewProfile)
			
			; Delete the settings file for recreation
			FileDelete, %MySettings%
			
			; Create a new settings file with modified contents
			FileAppend, %NewContent%, %MySettings%
			
			; Check if software is open, and close if it is
			Process, Exist, %SoftwareProcessName%
			if (ErrorLevel)
				Process, Close, %SoftwareProcessName%
				
			; Reopen sofware
			Run, %SoftwareExecutable%
			
			; Close splash screen:
			; Since the splash screen and main windows share the same window name, simply close the window and reopen it by rerunning the executable
			; This is kindof a double edged sword. If the splash screen doesn't appear sometime, the window will still be reopened due to the reason above
			; Wait for window to appear, time out in 5 seconds
			WinWait, %SoftwareWindowName%,, 5
			if (ErrorLevel)
				MsgBox, Waiting for window timed out
			else {
				; Close the window and rerun
				WinClose, %SoftwareWindowName%
				Run, %SoftwareExecutable%
			}
			
			; There is no point in looping through the rest of the lines, so exit the script now
			ExitApp
		}
	}
}

or:

Code: Select all

MySettings = C:\Users\2015 Win10\AppData\Local\Logitech\Logitech Gaming Software\settings.json ; Location of settings file
NewProfile = "persistentProfile" : "{5FAEA13C-DF17-44E4-8714-A0E9BF212D4E}"

SoftwareProcessName = LCore.exe ; Process name for closing the process -> Check taskmanager
SoftwareExecutable = C:\Program Files\Logitech Gaming Software\LCore.exe ; .exe file location
SoftwareWindowName = Logitech Gaming Software ; Check from Autohotkey's Window Spy to confirm

; First check if settings file exists
if (!FileExist(MySettings)) {
	MsgBox, File doesn't exist.
	ExitApp
}

; Read the file contents into a variable
FileRead, FileContent, %MySettings%

Loop, Parse, FileContent, `n, `r
{
	; A_LoopField contains the current line of the loop
	; If the current line contains "persistentProfile", then proceed to the block below
	if (InStr(A_LoopField, "persistentProfile")) {
	
		; A_LoopField contains "persistentProfile" so it's the current profile
		; If the profile is NOT equal to the value of NewProfile variable, then proceed to the block below
		if (A_LoopField != NewProfile) {
			
			; Replace the profile in the old file contents, then assign modified content to a variable
			NewContent := StrReplace(FileContent, A_LoopField, NewProfile)
			
			; Delete the settings file for recreation
			FileDelete, %MySettings%
			
			; Create a new settings file with modified contents
			FileAppend, %NewContent%, %MySettings%
			
			; Check if software is open, and close if it is
			Process, Exist, %SoftwareProcessName%
			if (ErrorLevel)
				Process, Close, %SoftwareProcessName%
				
			; Reopen sofware
			Run, %SoftwareExecutable%
			
			; Close splash screen:
			; Since the splash screen and main windows share the same window name, simply close the window once
			; Wait for window to appear, time out in 5 seconds
			WinWait, %SoftwareWindowName%,, 5
			if (ErrorLevel)
				MsgBox, Waiting for window timed out
			else WinClose, %SoftwareWindowName%
			
			; There is no point in looping through the rest of the lines, so exit the script now
			ExitApp
		}
	}
}
SmithyZoomZoom
Posts: 111
Joined: 23 Aug 2019, 23:32

Re: More elegant solution than ImageSearch to change mouse profile?

17 May 2020, 17:37

I tested your most recent revision:

Code: Select all

MySettings = C:\Users\2015 Win10\AppData\Local\Logitech\Logitech Gaming Software\settings.json ; Location of settings file
NewProfile = "persistentProfile" : "{5FAEA13C-DF17-44E4-8714-A0E9BF212D4E}"

SoftwareProcessName = LCore.exe ; Process name for closing the process -> Check taskmanager
SoftwareExecutable = C:\Program Files\Logitech Gaming Software\LCore.exe ; .exe file location
SoftwareWindowName = Logitech Gaming Software ; Check from Autohotkey's Window Spy to confirm

; First check if settings file exists
if (!FileExist(MySettings)) {
	MsgBox, File doesn't exist.
	ExitApp
}

; Read the file contents into a variable
FileRead, FileContent, %MySettings%

Loop, Parse, FileContent, `n, `r
{
	; A_LoopField contains the current line of the loop
	; If the current line contains "persistentProfile", then proceed to the block below
	if (InStr(A_LoopField, "persistentProfile")) {
	
		; A_LoopField contains "persistentProfile" so it's the current profile
		; If the profile is NOT equal to the value of NewProfile variable, then proceed to the block below
		if (A_LoopField != NewProfile) {
			
			; Replace the profile in the old file contents, then assign modified content to a variable
			NewContent := StrReplace(FileContent, A_LoopField, NewProfile)
			
			; Delete the settings file for recreation
			FileDelete, %MySettings%
			
			; Create a new settings file with modified contents
			FileAppend, %NewContent%, %MySettings%
			
			; Check if software is open, and close if it is
			Process, Exist, %SoftwareProcessName%
			if (ErrorLevel)
				Process, Close, %SoftwareProcessName%
				
			; Reopen sofware
			Run, %SoftwareExecutable%
			
			; Close splash screen:
			; Since the splash screen and main windows share the same window name, simply close the window and reopen it by rerunning the executable
			; This is kindof a double edged sword. If the splash screen doesn't appear sometime, the window will still be reopened due to the reason above
			; Wait for window to appear, time out in 10 seconds
			WinWait, %SoftwareWindowName%,, 10
			if (ErrorLevel)
				MsgBox, Waiting for window timed out
			else {
				; Close the window and rerun
				WinClose, %SoftwareWindowName%
				Run, %SoftwareExecutable%
			}
			
			; There is no point in looping through the rest of the lines, so exit the script now
			ExitApp
		}
	}
}
Sadly, the splash screen did not close. Neither did I receive the window timeout message box. As you consider the AutoHotkey script, be aware of my considerable gratitude for your reply.
SmithyZoomZoom
Posts: 111
Joined: 23 Aug 2019, 23:32

Re: More elegant solution than ImageSearch to change mouse profile?

21 May 2020, 22:00

If purely rewriting the file is not enough to get the splash screen to close, I am open to using Image Search to close the unwanted screen. My next post over the following few days may be me fiddling with the code to do that. :-)
SmithyZoomZoom
Posts: 111
Joined: 23 Aug 2019, 23:32

Re: More elegant solution than ImageSearch to change mouse profile?

28 May 2020, 16:26

I decided to use the Findclick library to facilitate an image search to click the X to close the splash screen window. Here is the final code:

Code: Select all

#Include FindClick.ahk

MySettings = C:\Users\2015 Win10\AppData\Local\Logitech\Logitech Gaming Software\settings.json ; Location of settings file
NewProfile = "persistentProfile" : "{5FAEA13C-DF17-44E4-8714-A0E9BF212D4E}"

SoftwareProcessName = LCore.exe ; Process name for closing the process -> Check taskmanager
SoftwareExecutable = C:\Program Files\Logitech Gaming Software\LCore.exe ; .exe file location
SoftwareWindowName = Logitech Gaming Software ; Check from Autohotkey's Window Spy to confirm

; First check if settings file exists
if (!FileExist(MySettings)) {
	MsgBox, File doesn't exist.
	ExitApp
}

; Read the file contents into a variable
FileRead, FileContent, %MySettings%

Loop, Parse, FileContent, `n, `r
{
	; A_LoopField contains the current line of the loop
	; If the current line contains "persistentProfile", then proceed to the block below
	if (InStr(A_LoopField, "persistentProfile")) {
	
		; A_LoopField contains "persistentProfile" so it's the current profile
		; If the profile is NOT equal to the value of NewProfile variable, then proceed to the block below
		if (A_LoopField != NewProfile) {
			
			; Replace the profile in the old file contents, then assign modified content to a variable
			NewContent := StrReplace(FileContent, A_LoopField, NewProfile)
			
			; Delete the settings file for recreation
			FileDelete, %MySettings%
			
			; Create a new settings file with modified contents
			FileAppend, %NewContent%, %MySettings%
			
			; Check if software is open, and close if it is
			Process, Exist, %SoftwareProcessName%
			if (ErrorLevel)
				Process, Close, %SoftwareProcessName%
				
			; Reopen sofware
			Run, %SoftwareExecutable%
			
			; Close splash screen:
			; Since the splash screen and main windows share the same window name, simply close the window and reopen it by rerunning the executable
			; This is kindof a double edged sword. If the splash screen doesn't appear sometime, the window will still be reopened due to the reason above
			; Wait for window to appear, time out in 10 seconds
			WinWait, %SoftwareWindowName%,, 10
			if (ErrorLevel)
				MsgBox, Waiting for window timed out
			else {
				; Close the window and rerun
				WinClose, %SoftwareWindowName%
				FindClick("D:\_Photographs and Scans\autohotkey_mouse_close", "Sleep50")
				Run, %SoftwareExecutable%
			}
			
			; There is no point in looping through the rest of the lines, so exit the script now
			ExitApp
		}
	}
}
Many thanks to all those who have responded to this thread, and to the invaluable @Cuadrix without whose expert help I would never have been able to complete the task!

Return to “Gaming Help (v1)”

Who is online

Users browsing this forum: No registered users and 72 guests