Jump to content

WinActive Problem??


Recommended Posts

Global $Paused
HotKeySet("`", "TogglePause")
HotKeySet("^q", "Terminate")

opt("WinTitleMatchMode", 2)

Local $TittleWindows[] = ['Firefox', 'Chrome']
While 1
   send('`')
   Switch WinActive($TittleWindows)
   case 'Firefox'
     ; WinWaitActive($TittleWindows[0])
      MsgBox(0, '', 'Firefox')
   case 'Chrome'
     ; WinWaitActive($TittleWindows[1])
      MsgBox(0, '', 'Chrome')
   EndSwitch
WEnd
;--------------------------------------------------------

Func TogglePause()
    $Paused = NOT $Paused
    While $Paused
        sleep(200)
        ToolTip('Script is "Paused"',0,0)
    WEnd
    ToolTip("")
EndFunc

Func Terminate()
    Exit 0
 EndFunc

Why It only run if Firefox is actived:(:(:(

Link to comment
Share on other sites

your script couldn't run as excpected:

  • you use a array instead of a Title or Hwnd
  • the return value is a Hwnd, but your switch argument is a string

so logic say's wether firefox nor chrom will be activated.

Edited by AutoBert
Link to comment
Share on other sites

Runs fine here, "`" unpauses the script and it shows "firefox"

The tricky bit for me is that, "`" means shift+´

Edited by careca
Spoiler

Renamer - Rename files and folders, remove portions of text from the filename etc.

GPO Tool - Export/Import Group policy settings.

MirrorDir - Synchronize/Backup/Mirror Folders

BeatsPlayer - Music player.

Params Tool - Right click an exe to see it's parameters or execute them.

String Trigger - Triggers pasting text or applications or internet links on specific strings.

Inconspicuous - Hide files in plain sight, not fully encrypted.

Regedit Control - Registry browsing history, quickly jump into any saved key.

Time4Shutdown - Write the time for shutdown in minutes.

Power Profiles Tool - Set a profile as active, delete, duplicate, export and import.

Finished Task Shutdown - Shuts down pc when specified window/Wndl/process closes.

NetworkSpeedShutdown - Shuts down pc if download speed goes under "X" Kb/s.

IUIAutomation - Topic with framework and examples

Au3Record.exe

Link to comment
Share on other sites

Basically what i meant is that it works fine here, but the hotkey is tricky to press in my keyboard, requires shift.

Spoiler

Renamer - Rename files and folders, remove portions of text from the filename etc.

GPO Tool - Export/Import Group policy settings.

MirrorDir - Synchronize/Backup/Mirror Folders

BeatsPlayer - Music player.

Params Tool - Right click an exe to see it's parameters or execute them.

String Trigger - Triggers pasting text or applications or internet links on specific strings.

Inconspicuous - Hide files in plain sight, not fully encrypted.

Regedit Control - Registry browsing history, quickly jump into any saved key.

Time4Shutdown - Write the time for shutdown in minutes.

Power Profiles Tool - Set a profile as active, delete, duplicate, export and import.

Finished Task Shutdown - Shuts down pc when specified window/Wndl/process closes.

NetworkSpeedShutdown - Shuts down pc if download speed goes under "X" Kb/s.

IUIAutomation - Topic with framework and examples

Au3Record.exe

Link to comment
Share on other sites

It does not work at all because the switch condition is testing an array against a string.

I have to say also that for a member of almost 8 years, the code is very poor and very speculative, that hotkey malarky with the send in the loop is quite disturbing.

 

AutoIt Absolute Beginners    Require a serial    Pause Script    Video Tutorials by Morthawt   ipify 

Monkey's are, like, natures humans.

Link to comment
Share on other sites

13 minutes ago, JohnOne said:

It does not work at all because the switch condition is testing an array against a string.

I have to say also that for a member of almost 8 years, the code is very poor and very speculative, that hotkey malarky with the send in the loop is quite disturbing.

 

 

 

That and there's no micro-sleep in the loop so this code will be a processor hog.  Perhaps that's what that toggle in the loop was for?

Edited by Blue_Drache

Lofting the cyberwinds on teknoleather wings, I am...The Blue Drache

Link to comment
Share on other sites

What do you think about this? I see now i made a mistake, when i said it worked, because it worked with firefox, and i didnt test with chrome. Apologies.

HotKeySet("{F1}", "TogglePause")
HotKeySet("{F2}", "Terminate")

Opt("WinTitleMatchMode", 2)
Local $Paused = 0

While 1
    If $Paused = 0 Then
        If WinActive('Firefox') Then MsgBox(0, '', 'Firefox')
        If WinActive('Chrome') Then MsgBox(0, '', 'Chrome')
    Else
        ToolTip('Script is "Paused"', 0, 0)
    EndIf
    Sleep(500)
WEnd

Func TogglePause()
    If $Paused = 1 Then
        $Paused = 0
        ToolTip("")
    Else
        $Paused = 1
        ToolTip('Script is "Paused"', 0, 0)
    EndIf
EndFunc   ;==>TogglePause

Func Terminate()
    Exit
EndFunc   ;==>Terminate

 

Edited by careca
Spoiler

Renamer - Rename files and folders, remove portions of text from the filename etc.

GPO Tool - Export/Import Group policy settings.

MirrorDir - Synchronize/Backup/Mirror Folders

BeatsPlayer - Music player.

Params Tool - Right click an exe to see it's parameters or execute them.

String Trigger - Triggers pasting text or applications or internet links on specific strings.

Inconspicuous - Hide files in plain sight, not fully encrypted.

Regedit Control - Registry browsing history, quickly jump into any saved key.

Time4Shutdown - Write the time for shutdown in minutes.

Power Profiles Tool - Set a profile as active, delete, duplicate, export and import.

Finished Task Shutdown - Shuts down pc when specified window/Wndl/process closes.

NetworkSpeedShutdown - Shuts down pc if download speed goes under "X" Kb/s.

IUIAutomation - Topic with framework and examples

Au3Record.exe

Link to comment
Share on other sites

My swift alteration.

Global $Paused
HotKeySet("`", "TogglePause")
HotKeySet("^q", "Terminate")

Opt("WinTitleMatchMode", 2)

Local $TittleWindows[] = ['Firefox', 'Chrome']
While 1
    ;send('`')
    Select
        Case WinActive($TittleWindows[0])
            MsgBox(0, '', $TittleWindows[0])
        Case WinActive($TittleWindows[1])
            MsgBox(0, '', $TittleWindows[1])
    EndSelect
    Sleep(100)
WEnd
;--------------------------------------------------------

Func TogglePause()
    $Paused = Not $Paused
    While $Paused
        Sleep(200)
        ToolTip('Script is "Paused"', 0, 0)
    WEnd
    ToolTip("")
EndFunc   ;==>TogglePause

Func Terminate()
    Exit 0
EndFunc   ;==>Terminate

But you cannot take OP word that the script works with firefox, because it does not, that was probably just a made up story.

Edited by JohnOne

AutoIt Absolute Beginners    Require a serial    Pause Script    Video Tutorials by Morthawt   ipify 

Monkey's are, like, natures humans.

Link to comment
Share on other sites

It worked here, only i didn't test with chrome, did you test it?

 

Spoiler

Renamer - Rename files and folders, remove portions of text from the filename etc.

GPO Tool - Export/Import Group policy settings.

MirrorDir - Synchronize/Backup/Mirror Folders

BeatsPlayer - Music player.

Params Tool - Right click an exe to see it's parameters or execute them.

String Trigger - Triggers pasting text or applications or internet links on specific strings.

Inconspicuous - Hide files in plain sight, not fully encrypted.

Regedit Control - Registry browsing history, quickly jump into any saved key.

Time4Shutdown - Write the time for shutdown in minutes.

Power Profiles Tool - Set a profile as active, delete, duplicate, export and import.

Finished Task Shutdown - Shuts down pc when specified window/Wndl/process closes.

NetworkSpeedShutdown - Shuts down pc if download speed goes under "X" Kb/s.

IUIAutomation - Topic with framework and examples

Au3Record.exe

Link to comment
Share on other sites

You keep saying that, but from the way i see it:

Opt("WinTitleMatchMode", 2) ;2=Match any substring
$TittleWindows[] = ['Firefox', 'Chrome']
WinActive($TittleWindows)

;Equivalent to:

WinActive('Firefox', 'Chrome')

;right? Where does the handle part comes from?
Spoiler

Renamer - Rename files and folders, remove portions of text from the filename etc.

GPO Tool - Export/Import Group policy settings.

MirrorDir - Synchronize/Backup/Mirror Folders

BeatsPlayer - Music player.

Params Tool - Right click an exe to see it's parameters or execute them.

String Trigger - Triggers pasting text or applications or internet links on specific strings.

Inconspicuous - Hide files in plain sight, not fully encrypted.

Regedit Control - Registry browsing history, quickly jump into any saved key.

Time4Shutdown - Write the time for shutdown in minutes.

Power Profiles Tool - Set a profile as active, delete, duplicate, export and import.

Finished Task Shutdown - Shuts down pc when specified window/Wndl/process closes.

NetworkSpeedShutdown - Shuts down pc if download speed goes under "X" Kb/s.

IUIAutomation - Topic with framework and examples

Au3Record.exe

Link to comment
Share on other sites

@JohnOne: Meanwhile i have tested OP's script. It always show's firefox-MsgBox even firefox isn't running. Try

ConsoleWrite(int(WinActive($TittleWindows))&@CRLF)

and you know why. As careca uses

If WinActive('Firefox') Then MsgBox(0, '', 'Firefox')
        If WinActive('Chrome') Then MsgBox(0, '', 'Chrome')

his script works correct. I couldn't test with Chrome but sure it does this job also.

Link to comment
Share on other sites

2 hours ago, AutoBert said:

@JohnOne: Meanwhile i have tested OP's script. It always show's firefox-MsgBox even firefox isn't running. Try

ConsoleWrite(int(WinActive($TittleWindows))&@CRLF)

and you know why. As careca uses

If WinActive('Firefox') Then MsgBox(0, '', 'Firefox')
        If WinActive('Chrome') Then MsgBox(0, '', 'Chrome')

his script works correct. I couldn't test with Chrome but sure it does this job also.

Of course the OP's script provides a false positive EVERY time for Firefox.  It's  comparing an integer with a string...a string (not empty) will be true...winactive will almost always return a handle...I'm not aware of a situation where some window has no focus (but prove me wrong :) ).

 

If the OP switched based on the active window's title, or class, it would have been fine...like:

#include <WinAPI.au3>
ConsoleWrite(_WinAPI_GetClassName(WinActive("[ACTIVE]")) & @CRLF)

output when the scite window is open:

SciTEWindow

 

IEbyXPATH-Grab IE DOM objects by XPATH IEscriptRecord-Makings of an IE script recorder ExcelFromXML-Create Excel docs without excel installed GetAllWindowControls-Output all control data on a given window.
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...