Jump to content

M23's interrupting topic, need help understanding


heyhey
 Share

Recommended Posts

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

; Set a HotKey
HotKeySet("x", "_Interrupt")

; Declare a flag
$fInterrupt = 0

$hGUI = GUICreate("Test", 500, 500)

$hButton_1 = GUICtrlCreateButton("Func One", 10, 10, 80, 30)
$hButton_2 = GUICtrlCreateButton("Func Two", 10, 50, 80, 30)

; Create a dummy control for the Accelerator to action when pressed
$hAccelInterupt = GUICtrlCreateDummy() ;I don't understand Accelerators                                     !
; Set an Accelerator key to action the dummy control
Dim $AccelKeys[1][2]=[ ["z", $hAccelInterupt] ]
GUISetAccelerators($AccelKeys)

GUISetState()

; Intercept Windows command messages with out own handler
GUIRegisterMsg($WM_COMMAND, "_WM_COMMAND")

While 1
    Switch GUIGetMsg()
    Case $GUI_EVENT_CLOSE ; What's the different between "Case" and "If"?                                   !
            Exit
        Case $hButton_1
            _Func_1()
        Case $hButton_2
            _Func_2()
    EndSwitch
WEnd

Func _Func_1()
    ; Make sure the flag is cleared
    $fInterrupt = 0
    For $i = 1 To 20
        ConsoleWrite("-Func 1 Running" & @CRLF);When I run this, it doesn't show any console, only GUI      !
        ; Look for the flag                    With func 1 and func 2 button, nothing else happens.         !
        If $fInterrupt <> 0 Then
            ; The flag was set
            Switch $fInterrupt
                Case 1
                    ConsoleWrite("!Func 1 interrrupted by Func 2" & @CRLF)
                Case 2
                    ConsoleWrite("!Func 1 interrrupted by HotKey" & @CRLF)
                Case 3
                    ConsoleWrite("!Func 1 interrrupted by Accelerator" & @CRLF)
            EndSwitch
            Return
        EndIf
        Sleep(100)
    Next
    ConsoleWrite(">Func 1 Ended" & @CRLF)
EndFunc

Func _Func_2()
    For $i = 1 To 3
        ConsoleWrite("+Func 2 Running" & @CRLF)
        Sleep(100)
    Next
    ConsoleWrite(">Func 2 Ended" & @CRLF)
EndFunc

Func _Interrupt()
    ; The HotKey was pressed so set the flag
    $fInterrupt = 2                             ;Am I right if this script says : when hotkey is pressed,   !
EndFunc                     ;It makes finterrupt 2, wich is not zero so the loop stops?                     !

Func _WM_COMMAND($hWnd, $Msg, $wParam, $lParam) ;I do not understand this whole function                    !
    ; The Func 2 button was pressed so set the flag
    If BitAND($wParam, 0x0000FFFF) =  $hButton_2 Then $fInterrupt = 1
    ; The dummy control was actioned by the Accelerator key so set the flag
    If BitAND($wParam, 0x0000FFFF) =  $hAccelInterupt Then $fInterrupt = 3
    Return $GUI_RUNDEFMSG
EndFunc   ;==>_WM_COMMAND

Hello, I want to become a little better in AutoIT learning how to make a "stop" button for my functions, I tryed using M23's topic / script, but I did not understand so much (I'm still young to scripting, and my english does not succeed in understanding everything)

So in the code above, sometimes I wrote and exhabition mark at the end of the line, in that mark, I wrote something myself (with ; ) and those are parts of the script that I do not understand, I thought this would be the best way to show you guys what I (don't) understand,

Please help me out , thanks in advance !

And for those who saw me before, this has nothing to do with the script I was attempting to make for a shotbot, this has nothing to do with game automation, I'm just trying to get a new start :)

Link to comment
Share on other sites

What do you mean you don't understand it? If you ever went to high school, you should know that saying "I don't understand" is not enough. You have to say what you don't understand.

Also, I don't see why understanding how this works helps you implement it. You can simply cut and paste from the example and it will work. If it doesn't work, then you need to show us code and ask to find the problem.

Link to comment
Share on other sites

did you read my whole question ? I have put the questions in the code, and why would I make something copypasted from someone else totally, that's more leeching than it's coding, and I would like to learn coding instead :)

Link to comment
Share on other sites

That is an alternative, however I'd like both a stop and a hotkey button

(Like in GUI , a buttons says "Stop (F9)) and the user either presses the stop button or the F9 key to stop the function

Also something simular with "pause (F8)" for example, so I thought that tutorial would help me , but I'm not skilled enhough to understand it.

Link to comment
Share on other sites

Excuse me, my browser was bugging horribly and I could only see the code above the fold.

1. I don't understand accelerators

Accelerators are hotkeys that only work in the active GUI. You can consider ctrl+z an accelerator that undoes the last made action. For it's syntax, I think the help file is sufficient.

2. Case vs If

$a = 1
If $a = 0 Then
  ; Do this
EndIF
If $a = 1 Then
  ; Do this
EndIF
If $a = 2 Or $a = 3 Then
 ; Do this
Endif

This is lots of typing work and it gets worse as you add more. Use select to reduce typing work required and increase readability:

Select
   Case $a = 0
      ; Do this
   Case $a = 1
      ; D o this
   Case $a = 2 Or $a = 3
      ; Do this
EndSelect

Switch is a special case of Select which you can use if:

1) You always use the same variable to test against

2) You only want to do comparison

That is true in the above case. So use switch, which really reduces typing required and greatly increases readability.

Switch $a
Case 0
; Do this
Case 1
; Do this
Case 2, 3
; Do this
EndSwitch

Sorry for missing tabs in last.

3. ;When I run this, it doesn't show any console, only GUI !

Open the .au3 file with SciTe, then run the script with F5. It will look like this:

Posted Image

4. Am I right if this script says : when hotkey is pressed, !

Correct.

5. _WM_COMMAND will come later. 8)

Link to comment
Share on other sites

Thanks aLOT for all your answers, what you've told me made me understand the whole thing , I'd like to thank both Manadar and M23, I think I'm able to make one myself now, I will try in a few minutes

And Manadar, just one more thing, so lets say I make WinWaitActive("Firefox") and execute the script in a firefox website or such, would an accelerator only wok when Firefox is open and a hotkey would work also while I'm doing other stuff?

Thank you so much.

Link to comment
Share on other sites

  • Developers

Also, I'm dutch also, if it's easyer to explain that way, go on :)

Thank you.

Ik ook en hoop dat je goed hebt begrepen waarom ik jou vorige topic heb gesloten.

Jos

Edited by Jos
grammar correction

SciTE4AutoIt3 Full installer Download page   - Beta files       Read before posting     How to post scriptsource   Forum etiquette  Forum Rules 
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Link to comment
Share on other sites

ROTFLMAO!!!!

That D*** dutchman used Google translator. Un-believable and Jos I'm ashamed of you for doing that.

George

Question about decompiling code? Read the decompiling FAQ and don't bother posting the question in the forums.

Be sure to read and follow the forum rules. -AKA the AutoIt Reading and Comprehension Skills test.***

The PCRE (Regular Expression) ToolKit for AutoIT - (Updated Oct 20, 2011 ver:3.0.1.13) - Please update your current version before filing any bug reports. The installer now includes both 32 and 64 bit versions. No change in version number.

Visit my Blog .. currently not active but it will soon be resplendent with news and views. Also please remove any links you may have to my website. it is soon to be closed and replaced with something else.

"Old age and treachery will always overcome youth and skill!"

Link to comment
Share on other sites

Het hele punt is dat Jos het Nederlands is.

Now that is Google.

EDIT: By the way, did you consider that he may have made a simple typographical error?

Edited by GEOSoft

George

Question about decompiling code? Read the decompiling FAQ and don't bother posting the question in the forums.

Be sure to read and follow the forum rules. -AKA the AutoIt Reading and Comprehension Skills test.***

The PCRE (Regular Expression) ToolKit for AutoIT - (Updated Oct 20, 2011 ver:3.0.1.13) - Please update your current version before filing any bug reports. The installer now includes both 32 and 64 bit versions. No change in version number.

Visit my Blog .. currently not active but it will soon be resplendent with news and views. Also please remove any links you may have to my website. it is soon to be closed and replaced with something else.

"Old age and treachery will always overcome youth and skill!"

Link to comment
Share on other sites

@About Manadars explanation of Select

I do believe ElseIf would be a better approximation. Since Select only run the first True Case.

$a = 1
If $a = 0 Then
  ; Do this
ElseIf $a = 1 Then
  ; Do this
ElseIf $a = 2 Or $a = 3 Then
 ; Do this
Endif
Link to comment
Share on other sites

I did, but it did not look like (It looks like this to me:)

normal sentence : I am cooking

Google sentence : I are cooking

Google makes that kind of errors alot, well, that's why I thought Jos used google translator, also the build of the sentence made it seem like he used Google Translator.

Link to comment
Share on other sites

A Swich would also work

$a = 1
Switch $a
    Case 0
      ; Do this
    Case 1
      ; Do this
    Case 2, 3
      ; Do this
EndSwitch

George

Question about decompiling code? Read the decompiling FAQ and don't bother posting the question in the forums.

Be sure to read and follow the forum rules. -AKA the AutoIt Reading and Comprehension Skills test.***

The PCRE (Regular Expression) ToolKit for AutoIT - (Updated Oct 20, 2011 ver:3.0.1.13) - Please update your current version before filing any bug reports. The installer now includes both 32 and 64 bit versions. No change in version number.

Visit my Blog .. currently not active but it will soon be resplendent with news and views. Also please remove any links you may have to my website. it is soon to be closed and replaced with something else.

"Old age and treachery will always overcome youth and skill!"

Link to comment
Share on other sites

I need help again , so this is my code I have made now :

#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
HotKeySet("^b","openmsn")
HotKeySet("^t","stopitunes")
HotKeySet("^e","teamspeak")
Opt("WinTitleMatchMode", 2)
$interrupt = 0
$hgui = GUICreate("Boyenn's pc bot",100,200,@DesktopWidth / 2 , @DesktopHeight / 2)
$button1 = GUICtrlCreateButton("Start",0,0,100,100)
$button2 = GUICtrlCreateButton("Pause",0,100,100,100)
GUISetState()
While 1
    Switch GUIGetMsg()
    case $button1
        button1()
    Case $button2
        button2()
    EndSwitch
WEnd

Func button1()
    $interrupt = 0
    Sleep(100)
    If $interrupt = 0 Then
        stopitunes()
        teamspeak()
        openmsn()
    EndIf
EndFunc     
Func stopitunes()
    $title=WinGetTitle("[active]")
    WinActivate("iTunes")
    Send("{SPACE}")
    Sleep(100)
    WinActivate($title)
EndFunc
Func teamspeak()
            Global $enable = 0
                If ProcessExists("ts3client_win64.exe") Then $enable = 1
                If $enable = 0 Then
                    Run("C:\Program Files\TeamSpeak 3 Client\ts3client_win64")
                    Sleep(1000)
                    WinActivate("Teamspeak 3")
                    Send("^s")
                    Send("{ENTER}")
                    sleep(1000)
                    Send("{ENTER}")
                EndIf
                If $enable = 1 Then
                    MsgBox(0,"Error","Je teamspeak staat al open.")
                EndIf
EndFunc
Func button2()
    $interrupt = 1
    MsgBox(0,"","tryed!")
EndFunc
Func openmsn()
WinActivate("Live")
EndFunc

Yes, I know, I just copy pasted the whole code.

But, there is something wrong, I tryed to copy M23's tutorial as good as possible, but when I click stop (button 2), the script wont stop, also, the msgbox won't appear.

Does anyone know what I did wrong?

Edit : I deleted the first loop, it does show the "tryed!" msgbox now, altough my interrupting functions still doesn't work, any help?

Edited by heyhey
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...