Jump to content
hoangakavn

I have a question, when i click button pause not work but when i press hotkey then ok

Recommended Posts

hoangakavn
Posted (edited)

I have a question, when i click button pause not work but when i press hotkey f3 then pause script, this is my code, i want when i click button pause then script pause . Tks All

#include <ButtonConstants.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <MsgBoxConstants.au3>

#Region ### START Koda GUI section ### Form=
$Form1 = GUICreate("Form1", 336, 72, 192, 124)
$btn_begin = GUICtrlCreateButton("Start Click", 16, 16, 137, 33)
$btn_pause = GUICtrlCreateButton("Pause / Resume", 184, 16, 137, 33)
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###

While 1
      HotKeySet("{f1}","begin")
   Sleep(50)
   HotKeySet("{f3}","pause")
   Sleep(50)
    $nMsg = GUIGetMsg()
    Switch $nMsg
    Case $GUI_EVENT_CLOSE
            Exit
         Case $btn_begin
            batdau()
         Case $btn_pause
            pause()
    EndSwitch
 WEnd

Func begin()
 Global   $g_bPaused = False
   For $i=1 to 10
   while 1
      MsgBox($MB_SYSTEMMODAL, "Title", "This message box will timeout after 10 seconds or select the OK button.", 10)
      Sleep(500)
   ExitLoop
   WEnd
Next
Sleep(50)
EndFunc
 Func pause()
   $g_bPaused = Not $g_bPaused
            While $g_bPaused
                Sleep(100)
                ToolTip('Script is Pause"', 500, 500)
            WEnd
EndFunc

 

Edited by hoangakavn

Share this post


Link to post
Share on other sites
BrewManNH

Try this, it's much better than what you have.

#include <ButtonConstants.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <MsgBoxConstants.au3>
Global $g_bPaused = False ; <<<<<<<<<< Global variables should be declared outside of functions.
HotKeySet("{f1}", "begin")
HotKeySet("{f3}", "pause")

#Region ### START Koda GUI section ### Form=
$Form1 = GUICreate("Form1", 336, 72, 192, 124)
$btn_begin = GUICtrlCreateButton("Start Click", 16, 16, 137, 33)
$btn_pause = GUICtrlCreateButton("Pause / Resume", 184, 16, 137, 33)
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###

While 1
;~  HotKeySet("{f1}", "begin")
;~  Sleep(50)
;~  HotKeySet("{f3}", "pause")
;~  Sleep(50)
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit
        Case $btn_begin
            begin()
        Case $btn_pause
            pause()
    EndSwitch
WEnd

Func begin()
;~  For $i = 1 To 10
;~      While 1 <<<<<<<<<<<<<< not sure why you think you need so many While loops
    MsgBox($MB_SYSTEMMODAL, "Title", "This message box will timeout after 10 seconds or select the OK button.", 10)
;~          Sleep(500) <<<<<<<<<<<<<<<<<< Unnecessary
;~          ExitLoop
;~      WEnd
;~  Next
;~  Sleep(50) <<<<<<<<<<<<<<< or so many sleep statements.
EndFunc   ;==>begin
Func pause()
    $g_bPaused = Not $g_bPaused
    While $g_bPaused
        ToolTip('Script is Paused"', 500, 500)
        $nMsg = GUIGetMsg()
        Switch $nMsg
            Case $btn_pause
                $g_bPaused = Not $g_bPaused
        EndSwitch
        Sleep(10)
    WEnd
    ToolTip('Script is not Paused"', 500, 500)

EndFunc   ;==>pause

 

  • Like 1

If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Share this post


Link to post
Share on other sites
hoangakavn
Posted (edited)

thank you for help me, but this not work if use while end, because this code is example == main code

;CreatGui....
#EndRegion ### END Koda GUI section ###

While 1
      HotKeySet("{f1}","Fam2NoxAdv")
   Sleep(50)
   HotKeySet("{f3}","pause")
   Sleep(50)
   HotKeySet("{f2}","thoat")
   Sleep(50)
    $nMsg = GUIGetMsg()
    Switch $nMsg
    Case $GUI_EVENT_CLOSE
            Exit
         Case $btn_autopanel
            autopanel()
         Case $btn_fix1
            fix1()
         Case $btn_fam_2nox_adv
            Fam2NoxAdv()
         Case $btn_thoat
            thoat()
         Case $btn_pause
            pause()
    EndSwitch
 WEnd
 
;fam 2 acc xem adv
Func Fam2NoxAdv()
Global $g_bPaused = False
For $i=1 to 1000
Sleep(3000)
ControlClick($hWnd,"","","left",2,308,12+30)
Sleep(500)
;neu full thi ban Do
   $color = PixelGetColor(465,286)
   $color1 = PixelGetColor(301,287)
   if $color = 0x9FEF53 or $color1 = 0x9EEE52 Then
      bando()
   Else
      ControlClick($hWnd,"","","left",2,308,12+30)
      Sleep(50)
      EndIf
While 1
   $color = PixelGetColor(662,96)
   $color1 = PixelGetColor(645,102)
   if $color = 0x58A16C or $color1 = 0xAFD2B9 Then
ControlClick($hWnd,"","","left",2,332,79)
Sleep(100)
ExitLoop
EndIf
WEnd

v.v...

Next
Sleep(50)
EndFunc

;pause script
Func pause()
   $g_bPaused = Not $g_bPaused
            While $g_bPaused
                Sleep(100)
                ToolTip('Script is pause"', 500, 500)
            WEnd
EndFunc

when i click button pause not work but when i press hotkey f3 then pause script, but i want when i click button pause func Fam2NoxAdv() is pause 

Edited by hoangakavn

Share this post


Link to post
Share on other sites
hoangakavn

i want stop func begin() with button pause, this loop is example

Func begin()
 Global   $g_bPaused = False
   For $i=1 to 10
   while 1
      MsgBox($MB_SYSTEMMODAL, "Title", "This message box will timeout after 10 seconds or select the OK button.", 10)
      Sleep(500)
   ExitLoop
   WEnd
Next
Sleep(50)
EndFunc

Share this post


Link to post
Share on other sites
BrewManNH

No idea what you're asking now, that's not the same question you asked at first.

Also, did you read the comments I put into the script I posted? Don't declare Global variables inside a function, move your HokeySets outside the functions/loops too, no reason for them to be in there.

What is your obsession with using Sleep statements?


If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Share this post


Link to post
Share on other sites
hoangakavn
Posted (edited)

if i press f3 func begin() is pause, but when i click button pause not work, why?. this is example

#include <ButtonConstants.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <MsgBoxConstants.au3>
Global $g_bPaused = False
HotKeySet("{f1}", "begin")
HotKeySet("{f3}", "pause")

#Region ### START Koda GUI section ### Form=
$Form1 = GUICreate("Form1", 336, 72, 192, 124)
$btn_begin = GUICtrlCreateButton("Start Click", 16, 16, 137, 33)
$btn_pause = GUICtrlCreateButton("Pause / Resume", 184, 16, 137, 33)
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###

While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit
        Case $btn_begin
            begin()
        Case $btn_pause ; if i press f3 func begin() is pause, but when i click button pause not work, why?
            pause()
    EndSwitch
WEnd

;Example
Func begin()
; loop is example, i need : when i click button btn_pause then func begin() will pause

;my code
   $color = PixelGetColor(465,286)
   $color1 = PixelGetColor(301,287)
   if $color30 = 0x9FEF53 or $color31 = 0x9EEE52 Then
      bando()
   Else
      ControlClick($hWnd,"","","left",2,308,12+30)
      Sleep(50)
      EndIf
While 1
   $color = PixelGetColor(662,96)
   $color1 = PixelGetColor(645,102)
   if $color = 0x58A16C or $color1 = 0xAFD2B9 Then
ControlClick($hWnd,"","","left",2,332,79)
Sleep(100)
ExitLoop
EndIf
WEnd
Sleep(1500)
ControlClick($hWnd,"","","left",2,577,349)
Sleep(1000)
   $color = PixelGetColor(378,350)
   $color1 = PixelGetColor(381,354)
   if $color = 0x9FEF53 or $color1 = 0x9AEA4E Then
      xemquangcao()
 Else
ControlClick($hWnd,"","","left",2,484,170)
Sleep(1000)
EndIf
Next
Sleep(50)
EndFunc

;you can test example, this same my code
; loop is example, i need : when i click button btn_pause then func begin() will pause
;For $i = 1 To 10
;While 1
;    MsgBox($MB_SYSTEMMODAL, "Title", "This message box will timeout after 10 seconds or select the OK button.", 10)
;         Sleep(500)
;WEnd



Func pause()
    $g_bPaused = Not $g_bPaused
    While $g_bPaused
        ToolTip('Script is Paused"', 500, 500)
        $nMsg = GUIGetMsg()
        Switch $nMsg
            Case $btn_pause
                $g_bPaused = Not $g_bPaused
        EndSwitch
        Sleep(10)
    WEnd
    ToolTip('Script is not Paused"', 500, 500)

EndFunc   ;==>pause

 

Edited by hoangakavn

Share this post


Link to post
Share on other sites
aa2zz6
Posted (edited)

I assume the issue is tied to the message box. Maybe swap it out for a ConsoleWrite("...") for testing purposes and it should work fine

 

While 1
    ConsoleWrite("test")
    ;MsgBox($MB_SYSTEMMODAL, "Title", "This message box will timeout after 10 seconds or select the OK button.", 10)
         Sleep(500)
WEnd

 

Edited by aa2zz6

Share this post


Link to post
Share on other sites
hoangakavn
Posted (edited)

i want when i click button pause then func Fam2NoxAdv() is pause

Func Fam2NoxAdv()

Can you edit script for me?

Edited by hoangakavn

Share this post


Link to post
Share on other sites
Jos
Posted (edited)

I understand what you want and told you something else which I hope you understood too.

As to your question: I fail to understand why you ask us to update your script which we are not able to run anyways as you only posted a portion!
Simply read the helpfile topic "GUI Reference - OnEvent Mode:" and use GUICtrlSetOnEvent() and figure it out yourself.

Jos 

Edited by Jos

Visit the SciTE4AutoIt3 Download page for the latest versions  - Beta files                                How to post scriptsource        Forum Rules
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Share this post


Link to post
Share on other sites
hoangakavn
1 hour ago, Jos said:

@hoangakavn,

Please don't create new topics for the same question and simply stick to the original!

Merged,

Jos

i'm so sorry, i'm newbie, thank you 

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

×