How to make Script working in just 1 Window

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
Yaruqii
Posts: 32
Joined: 11 Jul 2021, 16:29

How to make Script working in just 1 Window

Post by Yaruqii » 17 Oct 2021, 09:48

Hey, here I have a script, with an GUI, can someone code a drop down Menu Button into the GUI where you can choose on which Window the Script works, cause its a Anti Recoil Script, which when you hold the left Mouse button it drags down, and I want that that only works in the Game Window, so please add a Menu where you can choose the window, Thanks!

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 ,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
mikeyww
Posts: 26894
Joined: 09 Sep 2014, 18:38

Re: How to make Script working in just 1 Window

Post by mikeyww » 17 Oct 2021, 15:24

Here is a demonstration.

Code: Select all

Gui, Font, s10
Gui, Add, DropDownList, w400 vwin, % windows()
Gui, Add, Button, Default, OK
Gui, Show,, Select
Return

ButtonOK:
Gui, Submit
Return

#If WinActive(win) && win > ""
F3::Send y
#If

windows() {
 WinGet, wins, List
 Loop, %wins% {
  WinGet, style, Style, % wTitle := "ahk_id " wins%A_Index%
  WinGetTitle, winTitleText, %wTitle%
  list .= style ~= "0x(9|16)" || winTitleText = "" ? "" : winTitleText "`n"
 }
 Sort, list, U
 Return StrReplace(StrReplace(list, "`n", "|"), "|", "||",, 1)
}

Yaruqii
Posts: 32
Joined: 11 Jul 2021, 16:29

Re: How to make Script working in just 1 Window

Post by Yaruqii » 18 Oct 2021, 08:30

Sorry, but I cant Code myself, could you code it directlyin my script?

User avatar
mikeyww
Posts: 26894
Joined: 09 Sep 2014, 18:38

Re: How to make Script working in just 1 Window

Post by mikeyww » 18 Oct 2021, 09:26

Oh, sorry, perhaps I should not have replied. My approach would require a fair amount of work in reading, understanding, and changing the script. I was mostly providing a way to get the windows and then select one of them. Others may have simpler ideas here! I was using #If as an alternative to Hotkey.

The following kind of thing is the idea. I have not tested. Needs some adjustments, I think.

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 ,1
Gui, Add, CheckBox, xm+200 ym+67 vED gCheckBox, Toggle Script
Gui, Add, DropDownList, xm w280 vwin, % windows()
Gui, Add, Button, xm ym+60 w100, Apply Changes
Gui, Show, w300
Return

#If WinActive(win) && win > ""
LButton::
    Gui, Submit, NoHide
    SendInput, {LButton Down}
    SetTimer, DragDown, % 10 / Speed
Return

LButton Up::
    SendInput, {LButton Up}
    SetTimer, DragDown, Off
Return
#If

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

windows() {
 WinGet, wins, List
 Loop, %wins% {
  WinGet, style, Style, % wTitle := "ahk_id " wins%A_Index%
  WinGetTitle, winTitleText, %wTitle%
  list .= style ~= "0x(9|16)" || winTitleText = "" ? "" : winTitleText "`n"
 }
 Sort, list, U
 Return StrReplace(StrReplace(list, "`n", "|"), "|", "||",, 1)
}

Post Reply

Return to “Ask for Help (v1)”