Page 1 of 1

Help updating my script to V2

Posted: 29 Nov 2023, 19:26
by Jeff_f_f
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

Re: Help updating my script to V2

Posted: 29 Nov 2023, 20:18
by Datapoint
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
}

Re: Help updating my script to V2

Posted: 30 Nov 2023, 03:16
by vmech
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
}

Re: Help updating my script to V2

Posted: 30 Nov 2023, 17:27
by Jeff_f_f
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?

Re: Help updating my script to V2

Posted: 01 Dec 2023, 03:15
by vmech
@Jeff_f_f
Yes, get the Firefox :!: window title parameters using WindowSpy, and use them in the :!: WinActivate function.

Re: Help updating my script to V2

Posted: 01 Dec 2023, 10:11
by Jeff_f_f
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

Re: Help updating my script to V2  Topic is solved

Posted: 01 Dec 2023, 10:18
by vmech
@Jeff_f_f, try:

Code: Select all

WinActivate("ahk_class MozillaWindowClass ahk_exe firefox.exe")

Re: Help updating my script to V2

Posted: 01 Dec 2023, 15:12
by Jeff_f_f
Solved man, thank you so much...

Re: Help updating my script to V2

Posted: 02 Dec 2023, 06:57
by AHK_user
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