Need GUI for my Script

Ask gaming related questions (AHK v1.1 and older)
Yaruqii
Posts: 32
Joined: 11 Jul 2021, 16:29

Need GUI for my Script

16 Oct 2021, 13:34

Hey, here I have a Script, and I need a GUI for it.
It is a Script, when I press the Left Mouse Button, it drag down in a certain Speed, and I can toggle it with the "End" Key. In the GUI I want following points:
-A Button to Refresh the Script called: "Apply" or "Apply Changes"
-A checkbox, to Activate, and Deactivate the Script called: "Toggle Script"
-A Text Field to change the Hotkey for toggling the Funktion called: "Toggle-Hotkey:"
-A Text Field to change the Speed called: "Change Speed:"
Doesnt has to look good! Thanks!

Code: Select all

Speed = 1 ; between zero and infinity, exclusively
End::DragDown := !DragDown ;on/off with End
#If DragDown
~*LButton::SetTimer, DragDown,% 10/Speed
~*LButton Up::SetTimer, DragDown, Off
#If
DragDown:
DllCall("mouse_event", "UInt", 0x01, "UInt", 0, "UInt", 1+Speed)
Return
User avatar
Smile_
Posts: 857
Joined: 03 May 2020, 00:51

Re: Need GUI for my Script

16 Oct 2021, 15:00

A GUI containing the controls you asked for no less no more.

Code: Select all

Gui, Add, Button, xm ym w100, Refresh
Gui, Add, CheckBox, xm ym+30 vED gCheckBox, Enable/Disable
Gui, Add, Edit, xm ym+60 vHotkey w100, Hotkey
Gui, Add, Button, xm+105 ym+60 w100, Change Hotkey
Gui, Add, Edit, xm ym+90 vSpeed w100, Speed
Gui, Add, Button, xm+105 ym+90 w100, Change Speed
Gui, Show
Return

GuiClose:
ExitApp

ButtonRefresh:
   Gui, Submit, NoHide
   Msgbox, You pressed Refresh button
   ; To do list here.
Return

CheckBox:
   Gui, Submit, NoHide
   Msgbox, % (ED) ? "Checked" : "UnChecked"
   ; To do list here.
Return

ButtonChangeHotkey:
   Gui, Submit, NoHide
   Msgbox, Current hotkey set is "%Hotkey%"
   ; To do list here.
Return

ButtonChangeSpeed:
   Gui, Submit, NoHide
   Msgbox, Current Speed set is "%Speed%"
   ; To do list here.
Return
Yaruqii
Posts: 32
Joined: 11 Jul 2021, 16:29

Re: Need GUI for my Script

16 Oct 2021, 15:22

@Smile_ Thanks for your work, I really appreciate it, but the Activate, and deactivate button is not working, and I would like that theres No Msg Box after clicking a Button. Could you do this for me?
Thanks Mate!

Code: Select all

Gui, Add, Button, xm ym w100, Refresh
Gui, Add, CheckBox, xm ym+30 vED gCheckBox, Enable/Disable
Gui, Add, Edit, xm ym+60 vHotkey w100, Hotkey
Gui, Add, Button, xm+105 ym+60 w100, Change Hotkey
Gui, Add, Edit, xm ym+90 vSpeed w100, Speed
Gui, Add, Button, xm+105 ym+90 w100, Change Speed
Gui, Show
Return
GuiClose:
ExitApp
ButtonRefresh:
Gui, Submit, NoHide
Msgbox, You pressed Refresh button
; To do list here.
Return
CheckBox:
Gui, Submit, NoHide
Msgbox, % (ED) ? "Checked" : "UnChecked"
; To do list here.
Return
ButtonChangeHotkey:
Gui, Submit, NoHide
Msgbox, Current hotkey set is "%Hotkey%"
; To do list here.
Return
ButtonChangeSpeed:
Gui, Submit, NoHide
Msgbox, Current Speed set is "%Speed%"
; To do list here.

Speed = 1 ; between zero and infinity, exclusively
End::DragDown := !DragDown ;on/off with LeftAlt
#If DragDown
~*LButton::SetTimer, DragDown,% 10/Speed
~*LButton Up::SetTimer, DragDown, Off
#If
DragDown:
DllCall("mouse_event", "UInt", 0x01, "UInt", 0, "UInt", 1
User avatar
Smile_
Posts: 857
Joined: 03 May 2020, 00:51

Re: Need GUI for my Script

17 Oct 2021, 05:34

@Yaruqii
Try
I changed Left Button with Middle Button because left button is not helpful in this situation.

Code: Select all

Gui, Add, Text, xm ym+3, Hotkey:
Gui, Add, Hotkey, xm+40 ym vHotkeyC w240, % HotkeyCC := "End"
Hotkey, End, CheckBox
Gui, Add, Text, xm ym+33, Speed:
Gui, Add, Edit, xm+40 ym+30 vSpeed w240 Number, 1
Gui, Add, CheckBox, xm+200 ym+67 vED gCheckBox, Toggle Script
Gui, Add, Button, xm ym+60 w100, Apply Changes
Gui, Show, w300

Hotkey, MButton, LeftButton, Off
Hotkey, MButton Up, LeftButtonUp, Off
Return

GuiClose:
ExitApp

LeftButton:
    Gui, Submit, NoHide
    SendInput, {LButton Down}
    SetTimer, DragDown, % 10 / Speed
Return

LeftButtonUp:
    SendInput, {LButton Up}
    SetTimer, DragDown, Off
Return

DragDown:
    Gui, Submit, NoHide
    DllCall("mouse_event", "UInt", 0x01, "UInt", 0, "UInt", 1 + Speed)
Return

CheckBox:
    Gui, Submit, NoHide
    If (A_ThisHotkey = HotkeyCC)
        GuiControl,, ED, % !ED
    Gui, Submit, NoHide
    Stat := (ED) ? "On" : "Off"
    Hotkey, MButton, % Stat
    Hotkey, MButton Up, % Stat
Return

ButtonApplyChanges:
    Gui, Submit, NoHide
    If (HotkeyC != HotkeyCC) {
        Hotkey, % HotkeyCC, CheckBox, Off
        Hotkey, % HotkeyCC := HotkeyC, CheckBox, On
    }
Return
Yaruqii
Posts: 32
Joined: 11 Jul 2021, 16:29

Re: Need GUI for my Script

17 Oct 2021, 06:05

Thanks, I edited the code like this, and now everythings fine but at the Speed I CANT change it to for example to 0.5 or 2.5 Can you just fix that only thing? In the other Points its perfect! Thanks Mate

Code: Select all

Gui, Add, Text, xm ym+3, Hotkey:
Gui, Add, Hotkey, xm+40 ym vHotkeyC w240, % HotkeyCC := "End"
Hotkey, End, CheckBox
Gui, Add, Text, xm ym+33, Speed:
Gui, Add, Edit, xm+40 ym+30 vSpeed w240 Number, 1
Gui, Add, CheckBox, xm+200 ym+67 vED gCheckBox, Toggle Script
Gui, Add, Button, xm ym+60 w100, Apply Changes
Gui, Show, w300

Hotkey, LButton, LeftButton, Off
Hotkey, LButton Up, LeftButtonUp, Off
Return

GuiClose:
ExitApp

LeftButton:
    Gui, Submit, NoHide
    SendInput, {LButton Down}
    SetTimer, DragDown, % 10 / Speed
Return

LeftButtonUp:
    SendInput, {LButton Up}
    SetTimer, DragDown, Off
Return

DragDown:
    Gui, Submit, NoHide
    DllCall("mouse_event", "UInt", 0x01, "UInt", 0, "UInt", 1 + Speed)
Return

CheckBox:
    Gui, Submit, NoHide
    If (A_ThisHotkey = HotkeyCC)
        GuiControl,, ED, % !ED
    Gui, Submit, NoHide
    Stat := (ED) ? "On" : "Off"
    Hotkey, LButton, % Stat
    Hotkey, LButton Up, % Stat
Return

ButtonApplyChanges:
    Gui, Submit, NoHide
    If (HotkeyC != HotkeyCC) {
        Hotkey, % HotkeyCC, CheckBox, Off
        Hotkey, % HotkeyCC := HotkeyC, CheckBox, On
    }
Return
User avatar
Smile_
Posts: 857
Joined: 03 May 2020, 00:51

Re: Need GUI for my Script

17 Oct 2021, 06:16

Remove Number option from Gui, Add, Edit, xm+40 ym+30 vSpeed w240 Number, 1
Yaruqii
Posts: 32
Joined: 11 Jul 2021, 16:29

Re: Need GUI for my Script

17 Oct 2021, 07:15

@Smile_ Thanks it worked! Really appreciate your work. Can I post this script in the Working Scripts board with credits to you?
User avatar
Smile_
Posts: 857
Joined: 03 May 2020, 00:51

Re: Need GUI for my Script

17 Oct 2021, 11:47

No need to ask, feel free to do, there is no problem at all. :thumbup:
Confuzed84
Posts: 5
Joined: 24 Aug 2022, 03:25

Re: Need GUI for my Script

24 Aug 2022, 03:28

Hello all,
Sorry to bring back up this script from a long time ago...but. What part would you need to edit in order for it to go from dragging the mouse down to instead dragging the mouse up? I use inverted mouse and this pulls down instead of pushes up like I'd need it. Any help?
User avatar
Smile_
Posts: 857
Joined: 03 May 2020, 00:51

Re: Need GUI for my Script

24 Aug 2022, 13:08

@Confuzed84
Add a minus sign in the DllCall function to invert it, like this:

DllCall("mouse_event", "UInt", 0x01, "UInt", 0, "UInt", - (1 + Speed))
Confuzed84
Posts: 5
Joined: 24 Aug 2022, 03:25

Re: Need GUI for my Script

25 Aug 2022, 16:58

Thank you that worked perfect!! I had actually made it work by putting -1 - Speed, but yours is much cleaner, so I edited it match yours.

I do two other questions.

1.) Is there a way to make this macro only function when the mouse cursor is not visible? Ideally, I would only like it to work when the mouse cursor is invisible and then not function when it is visible.

2.) What code would I have to add to make it where I can adjust "Speed" on the fly? So say I wanted to utilize my [ key to subtract 1 speed and the ] key to add 1 speed.
Confuzed84
Posts: 5
Joined: 24 Aug 2022, 03:25

Re: Need GUI for my Script

29 Aug 2022, 10:52

Any help our direction on this would be greatly appreciated.
User avatar
Smile_
Posts: 857
Joined: 03 May 2020, 00:51

Re: Need GUI for my Script

29 Aug 2022, 11:45

Yes very possible, give me a second.
User avatar
Smile_
Posts: 857
Joined: 03 May 2020, 00:51

Re: Need GUI for my Script

29 Aug 2022, 13:16

OK try this,
I didn't add the mouse visibly check, I believe you want to enable the script only when you running your game.
If so, yes! that is will be much easier if you just check the active state of it window.

Code: Select all

#MaxHotkeysPerInterval 200
SetBatchLines, -1

Gui, -MinimizeBox
Gui, Margin, 10, 10
Gui, Font,  Bold, Consolas

Gui, Add, CheckBox, xm ym vED gCheckBox w200, Enable/Disable Script Hotkey:
Gui, Add, Hotkey, xm+200 yp-2 vHotkey w100 gApplyChanges, % Prev_Hotkey := "End"

Hotkey, End, CheckBoxH

Gui, Add, Text, xm yp+30 w50, Speed:
Gui, Add, Edit, xp+50 yp-2 vSpeed w250 Number, 1
Gui, Show

Hotkey, MButton, LeftButton, Off
Hotkey, MButton Up, LeftButtonUp, Off
Return

Esc::
GuiClose:
ExitApp

[::
    GuiControlGet, Speed,, Speed
    GuiControl,, Speed, % ++Speed
Return

]::
    GuiControlGet, Speed,, Speed
    GuiControl,, Speed, % --Speed
Return

LeftButton:
    GuiControlGet, Speed,, Speed
    SendInput, {LButton Down}
    SetTimer, DragDown, % 10 / Speed
Return

LeftButtonUp:
    SendInput, {LButton Up}
    SetTimer, DragDown, Off
Return

DragDown:
    GuiControlGet, Speed,, Speed
    DllCall("mouse_event", "UInt", 0x01, "UInt", 0, "UInt", - 1 - Speed)
Return

CheckBoxH:
    GuiControlGet, ED,, ED
    GuiControl,, ED, % ED := !ED
    Hotkey, MButton, % Stat := (ED) ? "On" : "Off"
    Hotkey, MButton Up, % Stat
Return

CheckBox:
    GuiControlGet, ED,, ED
    Hotkey, MButton, % Stat := (ED) ? "On" : "Off"
    Hotkey, MButton Up, % Stat
Return

ApplyChanges:
    GuiControlGet, Hotkey,, Hotkey
    Hotkey, % Prev_Hotkey, CheckBox, Off
    Hotkey, % Prev_Hotkey := Hotkey, CheckBox, On
Return
Confuzed84
Posts: 5
Joined: 24 Aug 2022, 03:25

Re: Need GUI for my Script

29 Aug 2022, 16:17

Thank you for that. I've been testing it. It needed a little bit of tweaking to get it to work. I'm not sure I know exactly how to get the active window part to work as it technically is in the same window.

For example:
When aiming there is no cursor as it is using the crosshair.
When in the inventory (still in the game) - there is a crosshair present, but technically wouldn't that still be the "active window" as you're still in the game?
Confuzed84
Posts: 5
Joined: 24 Aug 2022, 03:25

Re: Need GUI for my Script

30 Aug 2022, 14:06

Smile_,
I think I've gotten close by applying a few different codes into one code. However, for some reason the isMouseShown() function does not suspend when the crosshair is visible. Can you tell me why? Something is missing or not set up to detect the correct thing to Suspend.

Code: Select all

#MaxHotkeysPerInterval 200
SetBatchLines, -1
isMouseShown()

Gui, -MinimizeBox
Gui, Margin, 10, 10
Gui, Font,  Bold, Consolas

Gui, Add, CheckBox, xm ym vED gCheckBox w200, Enable/Disable Script Hotkey:
Gui, Add, Hotkey, xm+200 yp-2 vHotkey w100 gApplyChanges, % Prev_Hotkey := "End"

Hotkey, End, CheckBoxH

Gui, Add, Text, xm yp+30 w50, Speed:
Gui, Add, Edit, xp+50 yp-2 vSpeed w250 Number, 10
Gui, Show

Hotkey, LButton, LeftButton, Off
Hotkey, LButton Up, LeftButtonUp, Off
Return

GuiClose:
ExitApp

isMouseShown()
{
   StructSize := A_PtrSize + 16
   VarSetCapacity(InfoStruct, StructSize)
   NumPut(StructSize, InfoStruct)
   DllCall("GetCursorInfo", UInt, &InfoStruct)
   Result := NumGet(Info+Struct, 8)

   if Result > 1
      return 1
   else
      return 0
}
Loop
{
   if isMouseShown() == 1
      Suspend On
   else
      Suspend Off

   Sleep 1
}

]::
    GuiControlGet, Speed,, Speed
    GuiControl,, Speed, % ++Speed
Return

[::
    GuiControlGet, Speed,, Speed
    GuiControl,, Speed, % --Speed
Return

LeftButton:
    GuiControlGet, Speed,, Speed
    SendInput, {LButton Down}
    SetTimer, DragDown, % 10 / Speed
Return

LeftButtonUp:
    SendInput, {LButton Up}
    SetTimer, DragDown, Off
Return

DragDown:
    GuiControlGet, Speed,, Speed
    DllCall("mouse_event", "UInt", 0x01, "UInt", 0, "UInt", - (1 + Speed))
Return

CheckBoxH:
    GuiControlGet, ED,, ED
    GuiControl,, ED, % ED := !ED
    Hotkey, LButton, % Stat := (ED) ? "On" : "Off"
    Hotkey, LButton Up, % Stat
Return

CheckBox:
    GuiControlGet, ED,, ED
    Hotkey, LButton, % Stat := (ED) ? "On" : "Off"
    Hotkey, LButton Up, % Stat
Return

ApplyChanges:
    GuiControlGet, Hotkey,, Hotkey
    Hotkey, % Prev_Hotkey, CheckBox, Off
    Hotkey, % Prev_Hotkey := Hotkey, CheckBox, On
Return

Return to “Gaming Help (v1)”

Who is online

Users browsing this forum: No registered users and 58 guests