I can make listbox selections in any tab and the code is executed, except in my first tab. The only selection that works in the Main tab is the first choice. The rest do not.
Code: Select all
#IfWinActive ahk_class Notepad
~Left & ~Right::
if WinExist("Putty Item Picker") {
; If the GUI exists, toggle between Notepad and the GUI
WinGet, active_id, ID, A
if (active_id = WinExist("ahk_class Notepad"))
WinActivate, Putty Item Picker
else
WinActivate, ahk_class Notepad
} else {
Gui, Destroy
Gui, +HwndGuiHwnd
Gui, font, s10, Arial
Gui, Add, Tab3, x0 y0 w247 h215 Border vTabName gTabChanged, Main||EAP|LPR|LSD
Gui, Tab, Main
Gui, Add, ListBox, x3 y25 w240 h190 vMainItemSelected gSendDoubleClickedItemMain,
(
Search Text|
Search Item|
Item Help Info|
Chronicles|
Interface Table|
Next 10 NURs|
Next 5 LABs
)
;GuiControl, Choose, MainItemSelected, 1
Gui,Tab, EAP
Gui, Add, ListBox, x3 y25 w240 h190 vEAPItemSelected gSendDoubleClickedItemEAP,
(
Allowed Frequencies - 10938|
Display Name - 10950|
Display Name Settings - 10921|
EAP Specific Specimen Source - 10700|
Order Composer Config (OCC) - 24210|
IP Composer Buttons - 11115|
IP Order Questions (LQL) - 10305
)
Gui, Tab, LPR
Gui, Add, ListBox, x3 y25 w240 h190 vLPRItemSelected gSendDoubleClickedItemLPR,
(
LPR Item - 11111
)
Gui, Tab, LSD
Gui, Add, ListBox, x3 y25 w240 h190 vLSDItemSelected gSendDoubleClickedItemLSD,
(
LSD Item - 22222
)
WinGetPos, winx, winy, winwidth, winheight, ahk_class Notepad
guiwidth := 247
guiheight := 215
guiy := winy + (winheight - guiheight) // 2
guix := winx + winwidth - guiwidth
Gui, Show, x%guix% y%guiy% w247 h215, Putty Item Picker
Gui, +AlwaysOnTop
Send, {Tab}
sleep, 100
SetTimer, CheckWindowNotActive, 200
#IfWinActive, Putty Item Picker
Left::Send,{Tab}{Left}
Right::Send,{Tab}{Right}
Left & Up::Send,{Tab}
Numpad0::Gosub, SendSelectedListItem
Enter::Gosub, SendSelectedListItem
NumpadEnter::Gosub, SendSelectedListItem
#If
CheckWindowNotActive:
if (!WinExist("Putty Item Picker"))
{
; Stop the timer if the window doesn't exist
SetTimer, CheckWindowNotActive, Off
return
}
WinGetActiveTitle, activeWinTitle
; Specify the titles of the windows to exclude
windowTitle1 := "Putty Item Picker"
windowTitle2 := "Notepad"
; Check if the active window is not one of the specified windows
if (activeWinTitle != windowTitle1 and !InStr(activeWinTitle, windowTitle2))
{
; Do something
WinSet, AlwaysOnTop, Off, Putty Item Picker
;WinActivate, %activeWinTitle%
;Activateonce := true
return
}else
if (InStr(activeWinTitle, windowTitle2) or activeWinTitle == windowTitle1){
WinSet, AlwaysOnTop, On, Putty Item Picker
WinGetPos, winx, winy, winwidth, winheight, ahk_class Notepad
guiwidth := 247
guiheight := 215
guiy2 := winy + (winheight - guiheight) // 2
guix2 := winx + winwidth - guiwidth
WinMove, Putty Item Picker, , %guix2%, %guiy2%
}
return
TabChanged:
Gui, Submit, Nohide
If (TabName == "Main"){
GuiControl, Choose, MainItemSelected, 1
GuiControl, Choose, EAPItemSelected, 0
GuiControl, Choose, LPRItemSelected, 0
GuiControl, Choose, LSDItemSelected, 0
GuiControl, Focus, MainItemSelected
}
If (TabName == "EAP"){
GuiControl, Choose, MainItemSelected, 0
GuiControl, Choose, EAPItemSelected, 1
GuiControl, Choose, LPRItemSelected, 0
GuiControl, Choose, LSDItemSelected, 0
GuiControl, Focus, EAPItemSelected
}
If (TabName == "LPR"){
GuiControl, Choose, MainItemSelected, 0
GuiControl, Choose, EAPItemSelected, 0
GuiControl, Choose, LPRItemSelected, 1
GuiControl, Choose, LSDItemSelected, 0
GuiControl, Focus, LPRItemSelected
}
If (TabName == "LSD"){
GuiControl, Choose, MainItemSelected, 0
GuiControl, Choose, EAPItemSelected, 0
GuiControl, Choose, LPRItemSelected, 0
GuiControl, Choose, LSDItemSelected, 1
GuiControl, Focus, LSDItemSelected
}
return
SendDoubleClickedItemEAP:
SetCapsLockState, Off
If (A_GuiControlEvent != "DoubleClick") ;If user didn't double click the listbox
Return ;Do nothing.
Gosub, SendSelectedListItem
return
SendDoubleClickedItemMain:
SetCapsLockState, Off
If (A_GuiControlEvent != "DoubleClick") ;If user didn't double click the listbox
Return ;Do nothing.
Gosub, SendSelectedListItem
return
SendDoubleClickedItemLPR:
SetCapsLockState, Off
If (A_GuiControlEvent != "DoubleClick") ;If user didn't double click the listbox
Return ;Do nothing.
Gosub, SendSelectedListItem
return
SendDoubleClickedItemLSD:
SetCapsLockState, Off
If (A_GuiControlEvent != "DoubleClick") ;If user didn't double click the listbox
Return ;Do nothing.
Gosub, SendSelectedListItem
return
; Define a routine to send only the numbers from the selected item in the listbox
SendSelectedListItem:
WinActivate, ahk_class Notepad ; Activate the Notepad window
Sleep, 200 ; Add a short delay to ensure activation completes
Gui, Submit, Nohide ; Submit the GUI content without hiding
Sleep, 100 ; Add a short delay for stability
If(!EAPItemSelected&&!LPRItemSelected&&!LSDItemSelected&&!MainItemSelected)
return
If(EAPItemSelected){
RegExMatch(EAPItemSelected, "(\d+)", EAPNumberMatch)
if(EAPNumbermatch1 != ""){
Sleep, 150
SendInput, %EAPNumberMatch1%
sleep, 250
}}
If(LPRItemSelected){
RegExMatch(LPRItemSelected, "(\d+)", LPRNumberMatch)
if(LPRNumbermatch1 != ""){
Sleep, 150
SendInput, %LPRNumberMatch1%
sleep, 250
}}
If(LSDItemSelected){
RegExMatch(LSDItemSelected, "(\d+)", LSDNumberMatch)
if(LSDNumbermatch1 != ""){
Sleep, 150
SendInput, %LSDNumberMatch1%
sleep, 250
}}
If(MainItemSelected == "Search Text"){
Sleep, 150
Send, SearchText Selected
sleep, 150
}
If(MainItemSelected == "Search Item"){
MsgBox, Item
Sleep, 150
Send, Item
sleep, 150
}
If(MainItemSelected = "Item Help Info"){
Sleep, 150
Send, Help
sleep, 150
}
If(MainItemSelected = "Chronicles"){
Sleep, 150
Send, Chron
sleep, 150
}
If(MainItemSelected = "Interface Table"){
Sleep, 175
Send, AIF
Sleep, 100
Send, 105000001{Enter}
sleep, 150
}
return
#IfWinNotActive ahk_class Notepad
~Left & ~Right::
WinActivate, ahk_class Notepad
return
}
return
Thanks