Help updating my script to V2 Topic is solved

Get help with using AutoHotkey (v2 or newer) and its commands and hotkeys
Jeff_f_f
Posts: 20
Joined: 29 Nov 2023, 19:19

Help updating my script to V2

29 Nov 2023, 19:26

Hi everyone, could someone help me to update the following script to the V2? I'm kinda new in AHK and any help will be appreciated... It's a list box where the user selects one predefined text, and after clicking Ok the script will send a click and the chosen text:

Code: Select all

Gui, New
Gui, Add, ListBox, w200 voptiontext, text1|text2|
Gui, Add, Button, Default gOK, OK
Gui, Show,
return
OK:
Gui, Submit
;KeyWait, LButton, D, L
Click, 642, 358
SendInput %optiontext%
ExitApp
User avatar
Datapoint
Posts: 340
Joined: 18 Mar 2018, 17:06

Re: Help updating my script to V2

29 Nov 2023, 20:18

Hello :wave: It might look something like this in v2.

Code: Select all

myGui := Gui()
myLB := myGui.AddListBox("w200 voptiontext", ["text1", "text2"])
myBtn := myGui.AddButton("Default", "OK")
myBtn.OnEvent("Click", MyBtn_Click)
myGui.Show()

MyBtn_Click(GuiCtrlObj, Info) {
	Click 642, 358
	Send myLB.Text
}
vmech
Posts: 467
Joined: 25 Aug 2019, 13:03

Re: Help updating my script to V2

30 Nov 2023, 03:16

Alternative:

Code: Select all

#Requires Autohotkey v2.0

MyGui := Gui()
MyGui.AddListBox("w200 voptiontext", ["text1","text2"])
MyGui.AddButton("Default", "OK").OnEvent("Click", OK)
MyGui.Show()

OK(*)
{
  obj := MyGui.Submit()
  ;KeyWait, LButton, D, L
  Click(642, 358)
  Send(obj.optiontext)
  ExitApp
}
Please post your script code inside [code] ... [/code] block. Thank you.
Jeff_f_f
Posts: 20
Joined: 29 Nov 2023, 19:19

Re: Help updating my script to V2

30 Nov 2023, 17:27

That one worked nice, but i noticed that when I select the text and hit enter, the previuos window (the window receiving the click and the text is a firefox window) is not active, I have to alternate/click back to it... Is there a way to make it like as soon as I hit enter, the firefox window comes back active again?
vmech
Posts: 467
Joined: 25 Aug 2019, 13:03

Re: Help updating my script to V2

01 Dec 2023, 03:15

@Jeff_f_f
Yes, get the Firefox :!: window title parameters using WindowSpy, and use them in the :!: WinActivate function.
Please post your script code inside [code] ... [/code] block. Thank you.
Jeff_f_f
Posts: 20
Joined: 29 Nov 2023, 19:19

Re: Help updating my script to V2

01 Dec 2023, 10:11

Oh man, thanks a lot, you are being very helpful... But could you tell me how do i put that on the code? This are the "Window Title, Class and Process":

Deactivate user — Mozilla Firefox
ahk_class MozillaWindowClass
ahk_exe firefox.exe
ahk_pid 14552
ahk_id 462852
vmech
Posts: 467
Joined: 25 Aug 2019, 13:03

Re: Help updating my script to V2  Topic is solved

01 Dec 2023, 10:18

@Jeff_f_f, try:

Code: Select all

WinActivate("ahk_class MozillaWindowClass ahk_exe firefox.exe")
Please post your script code inside [code] ... [/code] block. Thank you.
Jeff_f_f
Posts: 20
Joined: 29 Nov 2023, 19:19

Re: Help updating my script to V2

01 Dec 2023, 15:12

Solved man, thank you so much...
AHK_user
Posts: 523
Joined: 04 Dec 2015, 14:52
Location: Belgium

Re: Help updating my script to V2

02 Dec 2023, 06:57

The V1 to V2 convertor is now updated to handle this script.
Apparently the Gui, New command gave a small error.
https://github.com/mmikeww/AHK-v2-script-converter

Return to “Ask for Help (v2)”

Who is online

Users browsing this forum: DavidP, mikeyww and 72 guests