The first click does not work when clicking background window #IfWinActive

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
FlameOnion
Posts: 2
Joined: 01 Jun 2023, 03:44

The first click does not work when clicking background window #IfWinActive

Post by FlameOnion » 01 Jun 2023, 03:51

Code: Select all

#IfWinActive Games (D:)
$LButton::
OutputDebug 1

IF (A_TickCount > ABlock)
{
	SendInput, {LButton Down}
OutputDebug 2

	ABlock := A_TickCount + 1600 ;1600ms
	KeyWait, LButton
	SendInput, {LButton Up}
    OutputDebug 3
}
The first click does not execute code when clicking on background window "Games(D: )", how to workaround or fix this?

User avatar
mikeyww
Posts: 26754
Joined: 09 Sep 2014, 18:38

Re: The first click does not work when clicking background window #IfWinActive

Post by mikeyww » 01 Jun 2023, 05:47

Welcome to this AutoHotkey forum!

You can check for a mouseover.

Code: Select all

#Requires AutoHotkey v1.1.33
winTitle := "ahk_exe notepad.exe"

#If mouseOver(winTitle)
LButton::MsgBox Test
#If

mouseOver(winTitle) {
 MouseGetPos,,, hWnd
 Return WinExist(winTitle " ahk_id" hWnd)
}

FlameOnion
Posts: 2
Joined: 01 Jun 2023, 03:44

Re: The first click does not work when clicking background window #IfWinActive

Post by FlameOnion » 01 Jun 2023, 13:36

mikeyww wrote:
01 Jun 2023, 05:47
Welcome to this AutoHotkey forum!

You can check for a mouseover.

Code: Select all

#Requires AutoHotkey v1.1.33
winTitle := "ahk_exe notepad.exe"

#If mouseOver(winTitle)
LButton::MsgBox Test
#If

mouseOver(winTitle) {
 MouseGetPos,,, hWnd
 Return WinExist(winTitle " ahk_id" hWnd)
}
I don't know what to do with that.I want to make it work with "IfWinActive Games (D:)" or "#IfWinActive ahk_class CabinetWClass" .
There are .ini(anu.ini) file in specific folders, and inside the ini is a .exe name.So when double clicking the folder it will exec the .exe and does not open the folder.
It works normally if the window "Games (D:)" is active, but when is in background/not active and double clicking the folder that has the .ini, it opens the folder and does not exec the .exe. With IfWinActive removed before the hotkey, there is no problem if the "Games (D:)" is in background and double clicking the folder that has the .ini. But want to use IfWinActive, to not potentially have issues in other apps or games.

Code: Select all

;#IfWinActive ahk_class CabinetWClass ; if (Foc = "DirectUIHWND3")
#IfWinActive Games (D:)
$LButton::

IF (A_TickCount > ABlock)                   ;https://www.autohotkey.com/boards/viewtopic.php?style=19&p=466941#p466941
{
	SendInput, {LButton Down}
OutputDebug 2

	ABlock := A_TickCount + 400 ;1600ms
	KeyWait, LButton
	SendInput, {LButton Up}
    OutputDebug 3
}
else
{
 dir := Explorer_GetSelection()
 dir_ini := dir . "\" . "anu.ini"
If FileExist(dir_ini)
{
    IniRead, var_exe, %dir_ini%, SectionNameRun
    Run,%comspec% /c "%dir%\%var_exe%",%dir%,hide ; cu asta la blood, nu mai arata la cursor clepsidra

  }
else
{
  SendInput, {LButton Down}
  KeyWait, LButton
	SendInput, {LButton Up}
}
}

;Loop, %la%  ; For each parameter:
;{
;OutputDebug,[sa]
;}
Return




Explorer_GetSelection() {                        ; https://www.autohotkey.com/boards/viewtopic.php?t=60403#p255169
   WinGetClass, winClass, % "ahk_id" . hWnd := WinExist("A")
   if !(winClass ~="Progman|WorkerW|(Cabinet|Explore)WClass")
      Return

   shellWindows := ComObjCreate("Shell.Application").Windows
   if (winClass ~= "Progman|WorkerW")
      shellFolderView := shellWindows.FindWindowSW(0, 0, SWC_DESKTOP := 8, 0, SWFO_NEEDDISPATCH := 1).Document
   else {
      for window in shellWindows
         if (hWnd = window.HWND) && (shellFolderView := window.Document)
            break
   }
   for item in shellFolderView.SelectedItems
      result .= (result = "" ? "" : "`n") . item.Path
   if !result
      result := shellFolderView.Folder.Self.Path
   Return result
}

Disable(Hotkey="RButton", MS=1000) {
	Hotkey, %Hotkey%, Disable_Return
	Sleep, %MS%
	Hotkey, %Hotkey%, Off

	Disable_Return:
	return
}
;;;;;;;;;;;;

Selected_Items()                    ;https://www.autohotkey.com/board/topic/122217-how-to-identify-a-selected-file/
{
  If WinActive("ahk_class CabinetWClass")                       ; EXPLORER WINDOW
  {
    for window in ComObjCreate("Shell.Application").Windows
      if window.HWND = WinExist("A")
        this_window := window

    if(this_window.Document.SelectedItems.Count > 1)
    {
      these_items := ""
      for item in this_window.Document.SelectedItems
        these_items .= item.Path . "`n"
      return these_items
    }
    else
      return this_window.Document.FocusedItem.Path
  }
}
;;;;;;;;;;;;;;;;;;;;

User avatar
mikeyww
Posts: 26754
Joined: 09 Sep 2014, 18:38

Re: The first click does not work when clicking background window #IfWinActive

Post by mikeyww » 02 Jun 2023, 08:08

Idea:

Code: Select all

#Requires AutoHotkey v1.1.33
winTitle1 := "Games (D:)"
winTitle2 := "ahk_class CabinetWClass"

#If mouseOver(winTitle1, winTitle2) ; Check for mouse over either WinTitle
LButton::
MsgBox Test ; Replace this with your code for this hotkey
Return
#If

mouseOver(winTitle*) {
 MouseGetPos,,, hWnd
 For each, title in winTitle
  If WinExist(title " ahk_id" hWnd)
   Return True
}
Before you change this script, try it to see if the MsgBox works. That tells you whether you have a working starting point.

Post Reply

Return to “Ask for Help (v1)”