Jump to content

Why wont both scripts stay on?


Recommended Posts

I have a easy GUI I made with relatively easy commands within it.

Im using checkboxs and for some reason I cant get the commands to work unless i only run one by itself.

If i try checking two checkboxs it only registers and runs the first one i clicked not the second one.

What can be the reason for this? I tried a few little things, changing the order of the scripts and functions, rewriting them a little and even addings whiles and wends and nothing happened really just the same results over and over.

If anyone has any ideas any solutions please post em and Id greatly appreciate it.

Please and thank you guys,

I'll happily post the GUI if someone wants to see they lay out of it all.

Link to comment
Share on other sites

I'll happily post the GUI if someone wants to see they lay out of it all.

It just so happens that I am a remote visualizer, I am examining your script now and by what I can telepathically see, you are using bad coding practices, you also need to improve your understanding of autoit script.

Link to comment
Share on other sites

replaced my clients name with Notepad;

The example I made (edited in) for you guys is now a little more easier to be seen.

Open note pad, and Tick "F1" and watch it spam "hihihihihihihihihi" in note pad, turn it off and it goes off, Now, I already KNOW that I got my Script looped because of the hotkey (I want it like that) But try ticking "Start Script" watch it spam "This is a test" which is fine thats how it should be.

But now, the problem;

try ticking F1 and Start Script or backwards and watch it only do one or the other (which ever is clicked first i believe) thats my problem here. Because I want it to do both functions at once, not one or the other..

Thanks again guys for the help

#include
#include
Opt('MustDeclareVars', 1)
Local $msg, $rolescale1, $rolescale60, $f1spam, $start, $dc, $goto
GUICreate("Acid Alchamy", 500, 200)
GUICtrlCreateButton("Quick Controls by Acid Alchamy", 0, 0, 500)
GUICtrlSetDefColor(0xFF0000)
GUICtrlCreateLabel("Ctrl+Pause/Break Key in [Notepad] Then Alt+1 to turn Controls [OFF]", 100,
25, 350)
GUICtrlSetDefColor(0xFFFFFF)
GUICtrlCreateGroup("RoleScale's", 5, 60, 110, 65)
$rolescale1 = GUICtrlCreateCheckbox("Invincible", 10, 80, 100, 20)
$rolescale60 = GUICtrlCreateCheckbox("Visible", 10, 100, 100, 20)
GUICtrlCreateGroup("", -99, -99, 1, 1) ;close group
GUICtrlCreateGroup("F Key Spams", 5, 160, 260, 40)
$f1spam = GUICtrlCreateCheckbox("Spam F1", 10, 175, 60, 20)
GUICtrlCreateGroup("", -99, -99, 1, 1) ;close group
$start = GUICtrlCreateCheckbox("Start Script", 300, 70, 70, 20)
$goto = GUICtrlCreateCheckbox("Go To Starting Point", 300, 100, 70, 20)
GUICtrlCreateGroup("DC", 405, 160, 90, 40)
GUICtrlCreateCheckbox("Disconnect", 420, 175, 80, 20)
GUICtrlCreateGroup("", -99, -99, 1, 1) ;close group
GUISetState()

HotKeySet("{numpad0}", "script")
HotKeySet("!{1}", "pTerminate")
HotKeySet("{F11}", "_Stop")

While 1
$msg = GUIGetMsg()
If $msg = $GUI_EVENT_CLOSE Then Exit
If IsChecked($rolescale1) Then RoleScale1(0)
If IsChecked($rolescale60) Then RoleScale60(0)
If IsChecked($f1spam) Then f1spam()
If IsChecked($start) Then script()
If IsChecked($goto) Then goto(0)
If IsChecked($dc) Then DC(0)
WEnd

Func DC($i)
While $i = 0
Opt("WinTitleMatchMode", 2)
WinActivate("Notepad", "")
Send("{Enter}")
ControlSend("Notepad", "", "", "{Enter}")
ControlSend("Notepad", "", "", "/break")
ControlSend("Notepad", "", "", "{Enter}")
ControlCommand("Acid Alchamy", "", $dc, "UnCheck", "")
$i = 1
WEnd
Return 1
EndFunc ;==>DC

Func RoleScale1($i)
While $i = 0
Opt("WinTitleMatchMode", 2)
WinActivate("Notepad", "")
Send("{Enter}")
ControlSend("Notepad", "", "", "{Enter}")
ControlSend("Notepad", "", "", "/rolescale 1")
ControlSend("Notepad", "", "", "{Enter}")
ControlCommand("Acid Alchamy", "", $rolescale1, "UnCheck", "")
$i = 1
WEnd
Return 1
EndFunc ;==>RoleScale1

Func RoleScale60($i)
While $i = 0
Opt("WinTitleMatchMode", 2)
WinActivate("Notepad", "")
Send("{Enter}")
ControlSend("Notepad", "", "", "{Enter}")
ControlSend("Notepad", "", "", "/rolescale 60")
ControlSend("Notepad", "", "", "{Enter}")
ControlCommand("Acid Alchamy", "", $rolescale60, "UnCheck", "")
$i = 1
WEnd
Return 1
EndFunc ;==>RoleScale60

Func f1spam()
Opt("WinTitleMatchMode", 2)
WinWaitActive("Notepad")
While 1
Send("hi")
WEnd
EndFunc ;==>f1spam

Func _Stop()
Exit 0
EndFunc ;==>_Stop
Func pTerminate()
Exit
EndFunc ;==>pTerminate

Func script()
Opt("WinTitleMatchMode", 2)
WinWaitActive("Notepad")
ControlSend("Notepad", "", "", "This is a test")
Send("{NUMPAD0}")
EndFunc ;==>script

Func goto($i)
While $i = 0
Opt("WinTitleMatchMode", 2)
WinActivate("Notepad", "")
ControlSend("Notepad", "", "", "This is not a test")
ControlCommand("Acid Alchamy", "", $goto, "UnCheck", "")
$i = 1
WEnd
Return 1
EndFunc ;==>goto

Func IsChecked($control)
Return BitAND(GUICtrlRead($control), $GUI_CHECKED) = $GUI_CHECKED
EndFunc ;==>IsChecked
Link to comment
Share on other sites

my goal is to get the GUI to actually put forth the two scripts at the same time. not one or the other.

I want both scripts if ticked to run at the same time.

AutoIt is single threaded, you can't have 2 parts of your script running at the same time, if they're in different scripts, you can have the first one run the second one, but not if they're in the same script.

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

Link to comment
Share on other sites

Wow that sorta sucks..

Now I feel like I'm gonna have to make seprate GUIs and then bind them together with a RUN command or something.. Geez I thought that this was something small I had made a mistake on; had no idea autoit really couldn't do it (seems so simple lol)

when using the run function; how can I get it to pick up on the name of my file regardless of where Its at?

Link to comment
Share on other sites

Wow that sorta sucks..

Now I feel like I'm gonna have to make seprate GUIs and then bind them together with a RUN command or something.. Geez I thought that this was something small I had made a mistake on; had no idea autoit really couldn't do it (seems so simple lol)

when using the run function; how can I get it to pick up on the name of my file regardless of where Its at?

Alternativly, you can have your script detect if it is the initial instance and launch multiple instances that will wait for a message from the initial instance.

This should get you started.

#Region ;**** Directives created by AutoIt3Wrapper_GUI ****
#AutoIt3Wrapper_UseUpx=n
#AutoIt3Wrapper_AU3Check_Parameters=-d -w 1 -w 2 -w 3 -w- 4 -w 5 -w 6 -w- 7
#AutoIt3Wrapper_Run_After=del /f /q "%scriptdir%%scriptfile%_Obfuscated.au3"
#EndRegion ;**** Directives created by AutoIt3Wrapper_GUI ****

If Not @Compiled Then Exit MsgBox(16, "Information!", "To lazy to write code for running without compiling, so you will need to compile this in order for the script to work correctly.")

#Include <GUIConstantsEx.au3>
#Include <WindowsConstants.au3>

#Include <WinAPI.au3>

AutoItSetOption("GUIOnEventMode", 1)
AutoItSetOption("GUIEventOptions", 1)

Global $Timer = TimerInit()
Global $OldTime = TimerDiff($Timer); Timing stuff for prevent duplicate calls

#region - Script Customized Singleton -
; We first register a windows message (or script message ;) look at _IPC_RegisterEvent('ASciTE')
; this way, when a user dropps files on the exe or activates us again, we either
; open the files in the previous ASciTE or activate our window
Global $AS_ACTIVATE = 100; used to tell ASciTE to activate its window
Global $AS_DROPPEDFILES = 200; used to tell ASciTE to open dropped files
Global $SM_ACTION; We will register a WM (Windows Message) to handle other initializations
Global $LoadCommand ; used for file path transfer
If @Compiled Then _IPC_RegisterEvent('Only One Instance');A uniqe identifying string name, here we intercept any other activity for quick processing, but it's a little random and doesn't work when it feels like it as it seems...
#endregion - Script Customized Singleton -

#Region - Example -

Global $Editor_UI = GUICreate("Drag and drop files on compiled script or reactivate script", 400, 300, -1, -1, BitOR($WS_CAPTION, $WS_SYSMENU, $WS_THICKFRAME, $WS_MINIMIZEBOX, $WS_MAXIMIZEBOX))
Global $hListView = GUICtrlCreateListView("Recieved from secondary instance", 0 , 0, 399, 299)
DllCall("user32.dll", "lresult", "SendMessageW", "hwnd", GUICtrlGetHandle($hListView), "uint", 0x1000 + 30, "wparam", 0, "lparam", 350)
GUISetOnEvent(-3, "_UI_Terminate")
GUISetState()

GUIRegisterMsg($SM_ACTION, "_IPC_RecieveMessage");IPC message, used to handle multiple instances (I.E., activating an existing instance or opening files dropped on our application executable)

Sleep(9999999)

#EndRegion - Example -

#region - Simple IPC -

#cs
Super simple IPC (Inter process communication)

_IPC_RegisterEvent($sOccurenceName) - Modified _singleton, it will register a mutex, and do some other neat stuff, like send a command to the existing process!
_IPC_BroadcastEvent($ID, $sText) - Posts a message to the existing process, ID specifies action to take, like calling a certain function, look at _IPC_RecieveMessage

_IPC_RecieveMessage([Default WM Params]) - Used only by the primary script to recive commands and variables
#ce

Func _IPC_RegisterEvent($sOccurenceName)
Local Const $ERROR_ALREADY_EXISTS = 183

Local $RT = DllCall("User32.dll", "int", "RegisterWindowMessageW", "WSTR", $sOccurenceName); Register our special message
If @error Or $RT[0] = 0 Then Return SetError(1, 0, 0);Doesn't matter if things don't work here, we'll just loose some misc features that don't even matter to normal operation
$SM_ACTION = $RT[0]; set global var so we can use it

DllCall("kernel32.dll", "handle", "CreateMutexW", "struct*", 0, "bool", 1, "wstr", $sOccurenceName); _Singlton() - I took it apart for what I needed only
If @error Then Return SetError(@error, @extended, 0)
Local $lastError = DllCall("kernel32.dll", "dword", "GetLastError")
If @error Then Return SetError(@error, @extended, 0)
If $lastError[0] = $ERROR_ALREADY_EXISTS Then
Switch $CmdLine[0]
Case True;Files dropped on exe, tell the preexisting instance that it should open these files quickly
Local $FileString
For $I = 0 To $CmdLine[0]
$FileString &= "<" & $CmdLine[$I] & ">";Wrap file strings to get the easily when recieving them
Next
_IPC_BroadcastEvent($AS_DROPPEDFILES, $FileString)
Case False; no files dropped, activate the initial instance!
_IPC_BroadcastEvent($AS_ACTIVATE, 0)
EndSwitch
Exit
Else; return because we are the initial instance
Return SetError(0, 0, 1)
EndIf
EndFunc ;==>_IPC_RegisterEvent

Func _IPC_BroadcastEvent($ID, $sText)
If Not $SM_ACTION Then Return
Local $Struct = DllStructCreate("uint;Char[" & StringLen($sText)+1 & "]")
DllStructSetData($Struct, 1, $ID)
DllStructSetData($Struct, 2, $sText)
Local $StructPtr = DllStructGetPtr($Struct)
DllCall("user32.dll", "lresult", "SendMessage", "hwnd", 0xFFFF, "uint", $SM_ACTION, "wparam", @AutoItPID, "lparam", $StructPtr);0xFFFF = all windows
EndFunc ;==>_IPC_BroadcastEvent

Func _IPC_RecieveMessage($hWnd, $Msg, $ProcessID, $Pointer)
#forceref $hwnd, $Msg
If (TimerDiff($Timer) - $OldTime) < 800 Then
; I don't know what I did wrong but suddenly the message is being double posted
; this is to prevent such bullshit from taking place.
MsgBox(0,"OldTime:"&$OldTime,"Stopped Action time:"&TimerDiff($Timer))
$OldTime = TimerDiff($Timer)
Return $GUI_RUNDEFMSG
EndIf

Local $hProcess = _WinAPI_OpenProcess(0x0010, False, $ProcessID)
If @error Then Return $GUI_RUNDEFMSG

Local $StructTag = "uint;Char[1024]"; structure that will hold the data... IPC = Inter process communication
Local $Struct = DllStructCreate($StructTag)
Local $StructSize = DllStructGetSize($Struct)
Local $StructPtr = DllStructGetPtr($Struct)
Local $iRead
_WinAPI_ReadProcessMemory($hProcess, $Pointer, $StructPtr, $StructSize, $iRead)

Switch DllStructGetData($Struct, 1)
Case $AS_ACTIVATE;Register the window activation since no files were dropped on the exe
AdlibRegister("_UI_Activate", 1500); Cannot activate from this function, use adlib to call it instead!
;Timing seems to be very important here, I have no idea why though

Case $AS_DROPPEDFILES; extract file strings and reister a function to deal with the $LoadCommand variable when we're done executing in the spectrum
Local $Files = StringRegExp(DllStructGetData($Struct, 2), "<(.*?)>", 3); get file strings passed
If IsArray($Files) Then
$LoadCommand = $Files
AdlibRegister("_UI_LoadCommand", 800)
;timing seems to be unimportant here, the process can be interupted safely as it seems...
EndIf

EndSwitch
$OldTime = TimerDiff($Timer)
Return $GUI_RUNDEFMSG
EndFunc ;==>_IPC_RecieveMessage

#endregion - Simple IPC -

Func _UI_Activate()
AdlibUnRegister("_UI_Activate")
GUICtrlCreateListViewItem("Activated by secondary instance!", $hListView)
GUISetState(@SW_RESTORE, $Editor_UI)
WinActivate($Editor_UI, "")
EndFunc ;==>_UI_Activate

; #FUNCTION# ====================================================================================================================
; Name ..........: _UI_LoadCommand
; Description ...: Used by the IPC functions to load files
; Syntax ........: _UI_LoadCommand()
; Parameters ....: None
; Return values .: None
; ===============================================================================================================================
Func _UI_LoadCommand()
Local $Pos = ControlGetPos($Editor_UI, "", $hListView)
GUICtrlDelete($hListView)
$hListView = GUICtrlCreateListView("Recieved from secondary instance",$Pos[0], $Pos[1], $pos[2], $Pos[3])
DllCall("user32.dll", "lresult", "SendMessageW", "hwnd", GUICtrlGetHandle($hListView), "uint", 0x1000 + 30, "wparam", 0, "lparam", 350)
AdlibUnRegister("_UI_LoadCommand")
If IsArray($LoadCommand) Then
For $I = 0 To UBound($LoadCommand) - 1
GUICtrlCreateListViewItem($LoadCommand[$I], $hListView)
Next
;~ _ArrayDisplay($LoadCommand)
$LoadCommand = 0
EndIf
Return 0
EndFunc ;==>_UI_LoadCommand

Func _UI_Terminate()
Exit
EndFunc
Edited by THAT1ANONYMOUSDUDE
Link to comment
Share on other sites

Automating games tends to be difficult. What you describe, though? Not so much.

Either way, thread locked since this is for a game. Conquer Online 2 or something like that.

Edited by Valik
Link to comment
Share on other sites

Guest
This topic is now closed to further replies.
 Share

  • Recently Browsing   0 members

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