Logitech G110 keyboard - problem with 2 SetTimers

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
Sir_MacCoy
Posts: 34
Joined: 04 Feb 2019, 23:17

Logitech G110 keyboard - problem with 2 SetTimers

17 Aug 2021, 09:22

Hi,

I've made a script with 2 SetTimers in it.
The first SetTimer (G-Keys) just needs to check continually if any of the specified windows appears. When it does, it closes the script. Of course it also has to stop checking once the script is closed.
The second SetTimer (StartProgramma) has to do a countdown. So, when the time is up it needs to execute a program that I have specified. So far, so good.

But my problem now is, when the condition SetTimer G-Keys is reached it exit the scripts, but it still executes the program under SetTimer StartProgramma, which I don't want to happen.
So basically what I want is: when one of the windows is matched under the condition SetTimer G-Keys it needs to exit the script, AND also stop executing the file under SetTimer StartProgramma.

I've tried to stop SetTimer StartProgamma with

Code: Select all

SetTimer, StartProgramma, Off
and

Code: Select all

SetTimer StartProgramma, Delete
but no succes.

I'm all out of ideas how to get this to work...
Can anyone please help me?
PS: The programs in the script are just examples.

Here's my script:

Code: Select all

#NoTrayIcon
#Persistent
#SingleInstance Ignore
SetTitleMatchMode, 3

Gui, New ,, G13
Gui, Add, Picture, w64 h64, C:\Program Files (x86)\Notepad++\notepad++.exe	; Shows icon of file
Gui, Add, Text,, Notepad++	; Name of program
Gui, +Owner -Caption
Gui, Show

SetTimer, G-Keys, 250
SetTimer, StartProgramma, -3000
return

G-Keys:
If Not WinExist("G1")
	{
	If Not WinExist("G2")
		{
		If Not WinExist("G3")
			{
			If Not WinExist("G4")
				{
				If Not WinExist("G5")
					{
					If Not WinExist("G6")
						{
						If Not WinExist("G7")
							{
							If Not WinExist("G8")
								{
								If Not WinExist("G9")
									{
									If Not WinExist("G10")
										{
										If Not WinExist("G11")
											{
											If Not WinExist("G12")
	{
	}}}}}}}}}}}}
else
	{
	ExitApp
	}
return

StartProgramma:
Run, "C:\Program Files (x86)\IrfanView\i_view32.exe"	; Execute file only when time is up and no G-windows are found
Exitapp

Esc::
ExitApp
User avatar
mikeyww
Posts: 27102
Joined: 09 Sep 2014, 18:38

Re: Problem with 2 SetTimers

17 Aug 2021, 09:52

The program obviously runs only if the script is still running. If the program should run only with certain conditions, then add those conditions before the run command. You don't need a timer to wait for a window: WinWait. You can use GroupAdd to define a window group, and then WinWait for that group. If the timeout occurs, run your program (or the opposite, if that is what you need).
Sir_MacCoy
Posts: 34
Joined: 04 Feb 2019, 23:17

Re: Problem with 2 SetTimers

17 Aug 2021, 17:30

mikeyww wrote:
17 Aug 2021, 09:52
The program obviously runs only if the script is still running. If the program should run only with certain conditions, then add those conditions before the run command. You don't need a timer to wait for a window: WinWait. You can use GroupAdd to define a window group, and then WinWait for that group. If the timeout occurs, run your program (or the opposite, if that is what you need).
Sorry, I don't know how to do this. I'm confused...
What do you mean with "certain conditions"? Like "If"?

Also I don't know how to put all those G-keys in one "WinWait" and "GroupAdd" function.
Can you give me more information how to do that please?
User avatar
gwarble
Posts: 524
Joined: 30 Sep 2013, 15:01

Re: Problem with 2 SetTimers

17 Aug 2021, 18:49

there’s a dozen ways to skin a cat, but my advice is to figure out the logic behind it (and simplify along the way until functional and understandable), then add back in what you need

on my phone so no testing, but looking at your logic, i think all the windows would have to exist (multiple negatives), so try instead to see if the window exists instead of not existing

also read about skipping the {} when a single line

then read about winwait and grouping and stuff when you want to improve it
EitherMouse - Multiple mice, individual settings . . . . www.EitherMouse.com . . . . forum . . . .
User avatar
mikeyww
Posts: 27102
Joined: 09 Sep 2014, 18:38

Re: Problem with 2 SetTimers

17 Aug 2021, 23:41

Code: Select all

EnvGet, pf86, ProgramFiles(x86)
Loop, 9
 GroupAdd, gWin, G%A_Index%
WinWait, ahk_group gWin,, 3
If ErrorLevel
 Run, %pf86%\IrfanView\i_view32.exe
ExitApp
Sir_MacCoy
Posts: 34
Joined: 04 Feb 2019, 23:17

Re: Problem with 2 SetTimers

18 Aug 2021, 10:50

mikeyww wrote:
17 Aug 2021, 23:41

Code: Select all

EnvGet, pf86, ProgramFiles(x86)
Loop, 9
 GroupAdd, gWin, G%A_Index%
WinWait, ahk_group gWin,, 3
If ErrorLevel
 Run, %pf86%\IrfanView\i_view32.exe
ExitApp
Thank you for your kindness and time.
I see what you are trying to do. But it works and don't work.
I will fully explain what I really want to achieve with this script. It might help you to get a better insight what I want to do.

So basically I own a Logitech G110 keyboard. That keyboard have 12 special "G-Keys", which I can assign to, to do many many things, like: open webbrowser, e-mailclient, a program, a macro,... so basically almost anything you can think of.
All those keys can be modified with the Logitech software. But I would rather like to see a mini splash screen of the program that I've binded that key to.
So e.g. when I press G1 I want to see some kind of splash screen (icon and text of the program will do) and if I don't press any other G-key within 3 seconds it has to execute the program.
The reason I want to do this, is because I have 3 x 12 G-Keys which I can toggle with 3 buttons on the board: M1, M2 and M3... so actually I have 36 possible keys I can bind to in total.

Image

There is no way I can memorize all of those keys. So now it happens when I press G1 and thinking it's my E-Mail, my webbrowser opens up and I realize E-Mail is probably under G2.
I've been thinking about of printing out labels and stick them to the keys. But that only works if I don't plan on using the same keys for M2 or M3. So I'm limited to 12 keys and that isn't really a solution.
That's why I thought it would come in handy to first see the icon and text of the program, before it launches itself. So, if I see I've pressed the wrong button, I still can "cancel" it if you will, by press another G-key.
Eventually I want to make 3 x 12 ahk scripts for each G-key, which I can assign to with the Logitech software.

I've modified it a bit to make it work, because when I pressed a key, it automatically closed itself again.

Code: Select all

GroupAdd, gWin, G%A_Index%,,, G3
I had to put an additional ExcludeTitle in, eg "G3" because the key I just pressed is in fact "G3" which i earlier on in the script specified.

Code: Select all

Gui, New ,, G3
Gui, Add, Picture, w64 h64, C:\Program Files (x86)\Mozilla Thunderbird\thunderbird.exe
Gui, Add, Text,, E-mail
Gui, +Owner -Caption
Gui, Show
After this tiny adjustment your script works, but when I press another G-key it doesn't execute the program of the last G-key I've pressed.
So, if I press G2 and then G3 (within 3 seconds), the program in G3 doesn't execute when those 3 seconds are over. I have both G-Keys assigned with each of your modified script and adjusted it accordingly to the programs I want to open with it.
If I press G2 (or G3) and do nothing, after 3 seconds the program starts. So that's okay.

I would very much appreciate it, if you have any other suggestions :)
Many thanks already for helping me out.

* Edit:
I think I've just figured out with Process Explorer what is happening.
If I press G2 and then G3 (within 3 seconds) it automatically closes the script for G3.
Maybe the reason this is happening is because the first script of G2 is still running when I press G3, and so there is no exception specified for G3 other then the window (G2) running at that moment.
User avatar
mikeyww
Posts: 27102
Joined: 09 Sep 2014, 18:38

Re: Problem with 2 SetTimers

18 Aug 2021, 18:06

Here is one way (a demonstration).

Code: Select all

dir = %A_ScriptDir%\pics
name := [["E-mail", "OUTLOOK"], ["Web", "msedge.exe"]]
Gui, Add, Picture, w64 h64 vpic
Gui, Add, Text   , wp  h20 vtxt

F1::
F2::
item := SubStr(A_ThisHotkey, 2)
GuiControl,, pic, %dir%\G%item%.png
GuiControl,, txt, % name[item].1
Gui, Show
SetTimer, Go, -3000
Return

Go:
Gui, Hide
Run, % name[item].2
Return
A variation:

Code: Select all

dir = %A_ScriptDir%\pics
app := {F1: ["E-mail", "OUTLOOK"], F2: ["Web", "msedge.exe"]}
Gui, Add, Picture, w64 h64 vpic
Gui, Add, Text   , wp  h20 vtxt

F1::
F2::
GuiControl,, pic, %dir%\%A_ThisHotkey%.png ; F1.png, F2.png
GuiControl,, txt, % app[A_ThisHotkey].1
Gui, Show
SetTimer, Go, -3000
Return

Go:
Gui, Hide
Run, % app[A_ThisHotkey].2
Return
Sir_MacCoy
Posts: 34
Joined: 04 Feb 2019, 23:17

Re: Problem with 2 SetTimers

18 Aug 2021, 18:51

I will check this later today when I have more time.
But it seems that you are programming all this to set up the F-keys?
I want to bind the G-keys of my keyboard, like you see in the picture above.
The problem is, I can' t bind them directly with Autohotkey.
There is no keymapping present for those keys, I' ve tried that already.
So, that won't work :(

* Edit: Can someone of the moderators perhaps modify the title of my topic, and add "Logitech G110 keyboard problem" or something like that to it. Maybe other users with a similar Logitech keyboard have some tips, how to solve this problem regarding setting up those G-Keys in Autohotkey. Thanks in advance!
User avatar
mikeyww
Posts: 27102
Joined: 09 Sep 2014, 18:38

Re: Problem with 2 SetTimers

18 Aug 2021, 19:25

Did you check for a scan code?
gregster
Posts: 9067
Joined: 30 Sep 2013, 06:48

Re: Problem with 2 SetTimers

18 Aug 2021, 22:16

Sir_MacCoy wrote:
18 Aug 2021, 18:51
* Edit: Can someone of the moderators perhaps modify the title of my topic, and add "Logitech G110 keyboard problem" or something like that to it.
Done - but that is something you could do yourself. By editing the first post of this topic (it's your own post) - there is a subject line at the top.
Sir_MacCoy
Posts: 34
Joined: 04 Feb 2019, 23:17

Re: Problem with 2 SetTimers

19 Aug 2021, 11:17

gregster wrote:
18 Aug 2021, 22:16
Sir_MacCoy wrote:
18 Aug 2021, 18:51
* Edit: Can someone of the moderators perhaps modify the title of my topic, and add "Logitech G110 keyboard problem" or something like that to it.
Done - but that is something you could do yourself. By editing the first post of this topic (it's your own post) - there is a subject line at the top.
Ah... sorry about that. I didn't know that... :crazy:
Thanks anyway :)

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: Darkmaster006, haomingchen1998 and 205 guests