Combine GUI commands and HotStrings?

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
nicknicknick
Posts: 12
Joined: 08 Apr 2022, 11:33

Combine GUI commands and HotStrings?

Post by nicknicknick » 19 May 2022, 14:53

I have created an ahk for my team at work.
There's a GUI (with abbreviated comments), that, when clicked, pastes in the full comment. It does this via: two matched lists, AltSubmit, and position. In the GUI it shows a keyboard shortcut for each of these comments:
image.png
image.png (53.04 KiB) Viewed 533 times
To the right, you can see the typed shortcut, which does the exact same thing as the GUI click... without the need for the GUI.

At first it wasn't a big deal, BUT the more I work on it the more I wonder if I can somehow combine the GUI click choice and the hot string? Right now, they are completely separate... they match, but they are separate. So when one needs to be modified, the other one does too. When a new one needs to be created, it needs to be created twice--once for the gui, once for the hotstring. (If I can't, that's okay. but it would be cool if I could)

Is there a theoretical way to combine the GUI click and the hotstrings?

Applicable abbreviated code:
Most of the GUI:

Code: Select all

 Gui, +Resize +hwndgooey
  Gui, font, s%ListBoxFontSize%, 
  Gui, add, tab, w480 h480,  Ops Notes | Courses | Shortcuts | Emails |
  Gui, Show, x%Xpos% y%Ypos% AutoSize, Scheduling
    Gui, tab, 1 ; OPS notes
	  Gui, Add, Text, , Click your choice* or type the shortcut  --> `t`t (shortcut)
	  Gui, Add, ListBox,  w460 r20 AltSubmit T110 vChoice gSubmit_All , % Choices ; 
	  Gui, Add, Text, , *Current Date + Your Initials will be added
    Gui, tab, 2 ; Courses

...ETC ETC

The Gosub:

Code: Select all

Submit_All: ;for submitting comments, Tab 1
	Gui, Submit, NoHide
	output := Comments[Choice]
	Gui, Destroy
	WinActivate, %prev% ; Opens last active window for pasting
	if output != " "; maybe the user didn't select anything?
		FormatTime, CurrentDateTime,, M/dd/yyyy
		SendInput, % CurrentDateTime output UsrInits ; 'Pastes' Date/Comment/User Initials into original (%prev%) window.
	return
The shown list and the pasted list:

Code: Select all

Choices:=("-Completed process. No action until instructed.`t(crpr)
|-Confirmation sent`t`t(conf)
|-Confirming Logistics sent `t`t(clsent)")

Code: Select all

Comments :=["-Completed our current process. No further action until instructed. "
, "-Confirmation email sent. "
, "-Confirming Logistics sent. "]
And one of the [separate] shortcut (they all basically follow this form):

Code: Select all

; -Confirmation email sent
::conf:: 
	FormatTime, CurrentDateTime,, M/dd/yyyy ; gets current date
	SendInput %CurrentDateTime%`-Confirmation email sent. %UsrInits%
return
It's probably pretty obvious that I understand some things but there are still huge holes in my ahk knowledge...Thanks in advance for your patience and knowledge-sharing!

BoBo
Posts: 6564
Joined: 13 May 2014, 17:15

Re: Combine GUI commands and HotStrings?

Post by BoBo » 19 May 2022, 15:11

TBH, the number of code snippets made me think "TL:DR". I'd prefer to see both scripts in full :silent:
I'd guess if you transfer your GUI options into an array, and create the Gui-options from the array, it shouldn't be a problem feeding your hotstrings from the same source.
JM2€ents

nicknicknick
Posts: 12
Joined: 08 Apr 2022, 11:33

Re: Combine GUI commands and HotStrings?

Post by nicknicknick » 19 May 2022, 15:35

Thanks for the reply!

Sorry about that--It's 600+ lines long and would need to be cleaned up because there's work information in it... I was hoping I could avoid sharing the whole thing...

As I was writing it out, I considered just having the GUI send the hotstring... not sure that can work. I think I will experiment w/ that.

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

Re: Combine GUI commands and HotStrings?

Post by mikeyww » 19 May 2022, 15:36

Code: Select all

Gui, Font, s10
Gui, Add, ListView, r10 w300 gPaste Grid ReadOnly AltSubmit, Hotstring|Description
Loop, Read, %A_ScriptFullPath%
 RegExMatch(A_LoopReadLine, ":.*:(.+)::\h+;(.+)", m) && LV_Add("", m1, Trim(m2))
LV_ModifyCol(1, 80)
Gosub, F3
F3::Gui, Show,, Paste (F3 = Show again)

Paste:
If !InStr(ErrorLevel, "S", True)
 Return
LV_GetText(hotstring, LV_GetNext())
Gui, Submit
Gosub, ::%hotstring% ; May need some adjustments here
Return

GuiEscape:
GuiClose:
Gui, Hide
Return

::conf:: ; Confirmation
SendInput {Text}This is the confirmation.
Return

::noconf:: ; Nope
SendInput {Text}This is not the confirmation.
Return

BoBo
Posts: 6564
Joined: 13 May 2014, 17:15

Re: Combine GUI commands and HotStrings?

Post by BoBo » 19 May 2022, 15:45

Concept

Code: Select all

; https://www.autohotkey.com/boards/viewtopic.php?f=76&t=104283&p=463113#p463113

Global arr :=  ["-Completed process. No action until instructed (crpr)"
               ,"-Confirmation sent (conf)"
               ,"-Confirming Logistics sent (clsent)"]      ; array that contains all your statements

Loop % arr.count()                                          ; create listbox options from array
   choices .= arr[A_Index] "|"
Gui, Add, Listbox,w270,% RTrim(choices,"|")                 ; add listbox options
Gui, Show,, Test
Sleep 3000
Gui, Destroy
Return

:x:crpr::str(1)                                             ; hotstring triggering the 1. array item/statement
:x:conf::str(2)
:x:clsent::str(3)

str(item) {
   clipboard := StrSplit(arr[item],"(").1                   ; copy statement from the array to the clipboard
   Send ^v                                                  ; paste the statement instead of sending it (faster!)
   }

nicknicknick
Posts: 12
Joined: 08 Apr 2022, 11:33

Re: Combine GUI commands and HotStrings?

Post by nicknicknick » 19 May 2022, 15:47

Thanks, mikeyww! A lot of that is over my head, but I will check it out, thoroughly after work! TY!

nicknicknick
Posts: 12
Joined: 08 Apr 2022, 11:33

Re: Combine GUI commands and HotStrings?

Post by nicknicknick » 19 May 2022, 15:49

Thank you as well, BoBo! Same I will have to digest this a bit tonight--I really appreciate your helP!

Post Reply

Return to “Ask for Help (v1)”