how can I combine two ahk scripts?

Get help with using AutoHotkey and its commands and hotkeys
ananthuthilakan
Posts: 65
Joined: 08 Jul 2019, 05:37

how can I combine two ahk scripts?

10 Jul 2019, 03:11

code of rcl.ahk

Code: Select all

Suspend on
F10::ExitApp
~Z::Suspend on 
~T::Suspend on
~Tab::Suspend on
~R::Suspend on
~Space::Suspend on
~Ctrl::Suspend on
~X::Suspend on
~RButton::Suspend 
~LButton::
   Loop ; Continuously loop until a 'break' command
    {
      if GetKeyState("LButton", "P") 
      { 
        Sleep 1 
        mouseXY(0, 12.5) 
        Sleep 1 
        mouseXY(0, 0) 
      }
      else ;LButton pressed? If no do this, i.e. exit the loop
        break ;will stop the loop
}
mouseXY(x,y)
{
  DllCall("mouse_event",uint,1,int,x,int,y,uint,0,int,0) ; moves the mouse could easily be the built in autohotkey MouseMove, X, Y
}
Startbutton

Code: Select all

; Generated by AutoGUI 2.6.0
#SingleInstance Force
#NoEnv
SetWorkingDir %A_ScriptDir%
SetBatchLines -1

Gui Add, Button, x47 y57 w162 h52 gstart, Start
Gui Show, w254 h162 , start
start:
Run rcl.ahk
return
GuiEscape:
GuiClose:
    ExitApp

how can I combine both ahk and still get the same result

when I press start button instead of running another ahk is there way to put the code in the same ahk and run that code

[Mod edit: Topic name added]
User avatar
eblanc
Posts: 71
Joined: 08 May 2019, 14:41

Re: how can I combine two ahk scripts?

10 Jul 2019, 10:18

I'm not understanding what you're scripts are suppossed to do, but its should be pretty straight forward.

Why can't join put them in the same script? What are you missing to bind them? couple of Label Markers?

Is the mouse suppossed to do this in the gui? or is the gui supossed to appear after the mouse does/finds something?
ananthuthilakan
Posts: 65
Joined: 08 Jul 2019, 05:37

Re: how can I combine two ahk scripts?

12 Jul 2019, 05:37

eblanc wrote:
10 Jul 2019, 10:18
I'm not understanding what you're scripts are suppossed to do, but its should be pretty straight forward.

Why can't join put them in the same script? What are you missing to bind them? couple of Label Markers?

Is the mouse suppossed to do this in the gui? or is the gui supossed to appear after the mouse does/finds something?
if i put both in the same code
even if i didnt press start button , the macro will be active

what i am trying to do is make start button for activating the macro and a stop button to deactivate the macro
User avatar
eblanc
Posts: 71
Joined: 08 May 2019, 14:41

Re: how can I combine two ahk scripts?

12 Jul 2019, 10:28

ananthuthilakan wrote:
12 Jul 2019, 05:37
eblanc wrote:
10 Jul 2019, 10:18
I'm not understanding what you're scripts are suppossed to do, but its should be pretty straight forward.

Why can't join put them in the same script? What are you missing to bind them? couple of Label Markers?

Is the mouse suppossed to do this in the gui? or is the gui supossed to appear after the mouse does/finds something?
if i put both in the same code
even if i didnt press start button , the macro will be active

what i am trying to do is make start button for activating the macro and a stop button to deactivate the macro
Start button could be anything, dealers choice: hotkey, hot string, pressing weird mouse buttons. etc..

For immediately stopping a script at any point I've found that adding a "Reload" function will clear the script. This basically is doing a run command on the AHK file you're running, reloading it. And that will stop and return the command at any point.
Didix
Posts: 15
Joined: 12 Jul 2019, 01:56

Re: how can I combine two ahk scripts?

13 Jul 2019, 00:22

eblanc wrote:
12 Jul 2019, 10:28
For immediately stopping a script at any point I've found that adding a "Reload" function will clear the script. This basically is doing a run command on the AHK file you're running, reloading it. And that will stop and return the command at any point.

How would you "Unload" a script?
User avatar
Xtra
Posts: 2038
Joined: 02 Oct 2015, 12:15

Re: how can I combine two ahk scripts?

13 Jul 2019, 04:25

Give this a try:

Code: Select all

; Generated by AutoGUI 2.6.0
#SingleInstance Force
#NoEnv
SetWorkingDir %A_ScriptDir%
SetBatchLines -1

Gui Add, Button, x47 y57 w162 h52 gstart, Start
Gui Show, w254 h162 , start
gosub, stop
return

start:
Suspend, Off
return

stop:
Suspend on
return

GuiEscape:
GuiClose:
F10::
    ExitApp

~Z::Suspend on 
~T::Suspend on
~Tab::Suspend on
~R::Suspend on
~Space::Suspend on
~Ctrl::Suspend on
~X::Suspend on
~RButton::Suspend 

~LButton::
Loop ; Continuously loop until a 'break' command
{
    if GetKeyState("LButton", "P") 
    { 
        Sleep 1 
        mouseXY(0, 12.5) 
        Sleep 1 
        mouseXY(0, 0) 
    }
    else ;LButton pressed? If no do this, i.e. exit the loop
        break ;will stop the loop
}
return

mouseXY(x,y)
{
  DllCall("mouse_event",uint,1,int,x,int,y,uint,0,int,0) ; moves the mouse could easily be the built in autohotkey MouseMove, X, Y
}
You can now add the stop button with a glabel named gstop.

HTH

Return to “Ask For Help”

Who is online

Users browsing this forum: Bing [Bot], downstairs, mikeyww, Ram, Vaklev and 45 guests