langthang084

WinActive Problem??

17 posts in this topic

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:(:(:(

Share this post


Link to post
Share on other sites



#3 ·  Posted (edited)

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

Share this post


Link to post
Share on other sites

#4 ·  Posted (edited)

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

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

Edited by careca

Spoiler

Paster - Main function is to paste text, but has more functions.

OpenW - Open With... alternative, Open any file with any application, set it's icon, set application as default.

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

BeatsPlayer - Music player.

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

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.

Firefox Profile Backup - Backup/restore previously saved profile.

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

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

 

Share this post


Link to post
Share on other sites

@AutoBert: I dont like use Hwnd because it will change each time application start. So how to solve my case with tittle??

@careca: I dont understand your trick very well :D

Share this post


Link to post
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

Paster - Main function is to paste text, but has more functions.

OpenW - Open With... alternative, Open any file with any application, set it's icon, set application as default.

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

BeatsPlayer - Music player.

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

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.

Firefox Profile Backup - Backup/restore previously saved profile.

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

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

 

Share this post


Link to post
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.

Share this post


Link to post
Share on other sites

#8 ·  Posted (edited)

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

Share this post


Link to post
Share on other sites

#9 ·  Posted (edited)

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

Paster - Main function is to paste text, but has more functions.

OpenW - Open With... alternative, Open any file with any application, set it's icon, set application as default.

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

BeatsPlayer - Music player.

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

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.

Firefox Profile Backup - Backup/restore previously saved profile.

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

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

 

Share this post


Link to post
Share on other sites

#10 ·  Posted (edited)

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.

Share this post


Link to post
Share on other sites

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

 


Spoiler

Paster - Main function is to paste text, but has more functions.

OpenW - Open With... alternative, Open any file with any application, set it's icon, set application as default.

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

BeatsPlayer - Music player.

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

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.

Firefox Profile Backup - Backup/restore previously saved profile.

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

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

 

Share this post


Link to post
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

Paster - Main function is to paste text, but has more functions.

OpenW - Open With... alternative, Open any file with any application, set it's icon, set application as default.

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

BeatsPlayer - Music player.

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

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.

Firefox Profile Backup - Backup/restore previously saved profile.

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

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

 

Share this post


Link to post
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.

Share this post


Link to post
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.

Share this post


Link to post
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