In Autohotkey, I have the following code :
^r::
Gui, Add, ListBox, Multi vMyListBox r10, Strawberries|Pears|Oranges|`r|Beans|Peas|Tomatoes|Turnips|
Gui, Add, Button, Default, OK
Gui, Show
return
ButtonOK:
Gui, Submit
MsgBox % MyListBox
send, % MyListBox
return
The output is, e.g. :
Strawberries|Beans|Turnips
But I would like it to be :
Strawberries, Beans, Turnips,
How should I proceed ?
Thanks in advance
Sounds like a job for RegEx.
Using RegExReplace() with the MyListBox variable as the haystack and "\|" as the needle. See this interactive for an explanation of this particular RegEx needle.
Saving the replaced version of the String in a variable called NewStr gives us this line of code:
NewStr := RegExReplace(MyListBox, "\|" , Replacement := ", ")
Current Code:
^r::
Gui, Add, ListBox, Multi vMyListBox r10, Strawberries|Pears|Oranges|`r|Beans|Peas|Tomatoes|Turnips|
Gui, Add, Button, Default, OK
Gui, Show
return
ButtonOK:
Gui, Submit
MsgBox % MyListBox
NewStr := RegExReplace(MyListBox, "\|" , Replacement := ", ")
MsgBox % NewStr
send, % NewStr
return
However, this version does not add a trailing ", ". In order to add this, let's just append a ", " to the NewStr variable we just created with NewStr.=", "
Final Code:
^r::
Gui, Add, ListBox, Multi vMyListBox r10, Strawberries|Pears|Oranges|`r|Beans|Peas|Tomatoes|Turnips|
Gui, Add, Button, Default, OK
Gui, Show
return
ButtonOK:
Gui, Submit
MsgBox % MyListBox
NewStr := RegExReplace(MyListBox, "\|" , Replacement := ", ")
NewStr.=", "
MsgBox % NewStr
send, % NewStr
return
Related
I've created a GUI using AHK. I am storing the Id and description as key-value pairs. I want to update the Desc when the user enters the ID with the corresponding desc stored in the associative array. How can I dynamically updated the GUI?
^h::
oKeys := []
oValues := []
oArray := {}
if (WinExist("ahk_id " hwndgui)) {
Gui, Destroy
return
}
gui, add, text,, Type:
Gui, Add, DropDownList,vType, TSO|PAX|DVI
gui, add, text,, ID:
Gui, Add, Edit, vId
gui, add, text,, Partial|Complete:
Gui, Add, DropDownList,vPartial, Partial||Complete
gui, add, text,, Left-Behind:
Gui, Add, DropDownList,vLeft, False||True
gui, add, text,, XFR-Type:
Gui, Add, DropDownList,vXFR, Standard||Contact|Theft
gui, add, text,, DESC:
Gui, Add, Edit, vDesc , oArray[(TypeId)]
Gui, Add, Button, Default gOK, OK
Gui, Show, Hide
Gui, +LastFound
hwndgui:=WinExist()
OK:
Gui, Submit
oKeys.Push((TypeId))
oValues.Push((Desc))
Loop, % oKeys.Length()
oArray[oKeys[A_Index]] := oValues[A_Index]
if WinExist("labelImg")
WinActivate ; Uses the last found window.
Send, ^a
Send, %Type%_%Id%_%Partial%_%Desc%
for vKey, vValue in oArray
vOutput .= vKey " " vValue "`r`n"
MsgBox, % vOutput
Gui, Show
return
I have the following script. I'm not sure how I can modify it to navigate the results using the up or down arrow keys. To run it, just create a .txt file and add some words in there (one word per line), then edit the filepath to where your .txt file is located. Then just search for a keyword that is found in at least 2 of the lines. e.g
Word1
Word2
If you search for word, it will return both word1 and word2. Then I just need to choose between them using up and down arrow key.
F9::
{
FilePath := "D:\5. Programs\AutoHotkey L x64\test.txt"
Gui, Destroy
Gui, Font, S20
Gui, Add, Text, X25 Y10 W450 H30 +Center , Search Box
Gui, Font, S10
Gui, Add, Edit, XP Y+20 W450 H20 vSearchString,
Gui, Color
Gui, Show, W500 H100, Search Box
return
#IfWinActive, Search Box
{
Enter::
Gui, Submit, NoHide
ResultList := []
ChosenString := ""
Loop, Read, %FilePath%
{
if (InStr(A_LoopReadLine, SearchString))
{
ResultList.Push(A_LoopReadLine)
}
}
if (!ResultList.Length())
{
;MsgBox % "No match found!"
return
}
Gui, DisplayResults:New,-MaximizeBox -MinimizeBox , Search results
Gui, Add, Text, w250, % "Click on one of the results below:"
for key, value in ResultList
{
if (key = 1)
Gui, Add, Radio, gSelectResult vChosenString, %value%
else
Gui, Add, Radio, gSelectResult, %value%
}
Gui, DisplayResults:Show
return
SelectResult:
Gui, DisplayResults:Submit
;Msgbox, % ResultList[ChosenString]
Clipboard := % ResultList[ChosenString]
return
}
}
return
You don't want the GUI to disappear?
Add NoHide in line number 44 like this:
Gui, DisplayResults:Submit, NoHide.
I'm trying a parsing loop, this works good except I can't delete the first item in the list. Probably something to do with the backtick n. Can't figure it out yet!
Update - OK, needed to duplicate the StringReplace line without a backtick n, so as to get the first item in the list.
Gui, Add, ListBox, 8 x26 y37 w100 h100 vColorChoice, Red|Green|Blue|Black|White
Gui +Delimiter`n
Gui, Add, Button, Default, Delete
Gui, show
return
ButtonDelete:
Gui, Submit, NoHide
ControlGet, ListBoxContents, List,, ListBox1
StringReplace, ListBoxContents, ListBoxContents, |, `n, All
msgbox %ColorChoice% ; ColorChoice here contains the files selected to delete
Loop, Parse, ColorChoice, `n
{
StringReplace, ListBoxContents, ListBoxContents, %A_LoopField%`n
StringReplace, ListBoxContents, ListBoxContents, %A_LoopField%
msgbox %ListBoxContents%
}
GuiControl,, ColorChoice, `n%ListBoxContents%
return
GuiClose:
ExitApp
Long paragraphs in Adobe Acrobat results in a line break when text is copied to clipboard and pasted in Word.
To deal with this, I manually paste the copied-text in Notepad ++ > select all > ctrl+J (join lines) > select all > Copy...... and then paste it into my Word document.
I would like to automate this join line using autohotkey as I have a large body of documents to go through. I can't seem to find any examples online in dealing with this directly within autohotkey script.
Ex.
Data structures with labeled axes supporting automatic or explicit data alignment.
This prevents common errors resulting from misaligned data and working with
differently-indexed data coming from different sources.
After manually joining in Notepad ++
Data structures with labeled axes supporting automatic or explicit data alignment. This prevents common errors resulting from misaligned data and working with differently-indexed data coming from different sources.
This works:
#Persistent
OnClipboardChange("ClipChanged")
return
ClipChanged() {
If (WinActive("ahk_exe AcroRd32.exe")) {
For e, v in StrSplit(clipboard, "`n", "`r")
x .= v " "
clipboard := trim(x)
}
}
Try this:
#Persistent
return
OnClipboardChange:
If WinActive("ahk_exe AcroRd32.exe")
{
clipboard =
Send, {Ctrl down}c{Ctrl up}{Esc}
ClipWait
clip := RegExReplace(clipboard, "(\S.*?)\R(.*?\S)", "$1 $2") ; strip line breaks and replace them with spaces
clipboard = %clip%
StringReplace clipboard, clipboard, % " ", % " ", A ; replace double spaces with single spaces
ClipWait
ControlClick, x0 y0, A
}
return
EDIT
Or this:
#Persistent
return
OnClipboardChange:
If WinActive("ahk_class AcrobatSDIWindow")
{
clipboard := ""
Send, {Ctrl down}c{Ctrl up}{Esc}
ClipWait
clip := RegExReplace(clipboard, "(\S.*?)\R(.*?\S)", "$1 $2") ; strip line breaks and replace them with spaces
StringReplace clip, clip, % " ", % " ", A ; replace double spaces with single spaces
clipboard := ""
clipboard = %clip%
ClipWait 2
If !(ErrorLevel)
{
ToolTip, lines joined
Sleep 500
ToolTip
}
}
return
I added functionality considering lines ending with a hyphen.
Before:
This occurs in elec-
tricity generation
systems.
After:
This occurs in electricity generation systems.
Code:
#Persistent
return
OnClipboardChange:
If WinActive("ahk_exe AcroRd32.exe")
{
clipboard := ""
Send, {Ctrl down}c{Ctrl up}{Esc}
ClipWait
clip := RegExReplace(clipboard, "(\S.*?)-\R(.*?\S)", "$1$2") ; strip line breaks with hyphen
clip := RegExReplace(clip, "(\S.*?)\R(.*?\S)", "$1 $2") ; strip line breaks and replace them with spaces
StringReplace clip, clip, % " ", % " ", A ; replace double spaces with single spaces
clipboard := ""
clipboard = %clip%
ClipWait 2
If !(ErrorLevel)
{
ToolTip, lines joined
Sleep 500
ToolTip
}
}
return
So I am trying to look for a specific text on the webpage and do a thing if the text was found, here is my current script:
!m::
clipboard =
text = my text here
Send, {Ctrl}+A
Sleep, 100
Send, {Ctrl}+C
var1 = %clipboard%
IfInString, var1, %text%
msgbox found the text
else
msgbox no text found
And regardless if the text is on the webpage or not, it always returns "no text found"
Any help on this?
P.S. I've also tried "if contains" and removing line breaks from the variable but the result is the same :(
StringReplace, var1, var1, `r `n, All
The send commands are not correct.
A command {Ctrl}+A, will press Ctrl, release it, and then press A. The lower case letter should also be used.
You should use either:
Send, {Ctrl down}{a}{Ctrl up}
or
Send, ^{a}
Do this for both Send commands.
A return commend should also be included as the end of the hotkey code
sequence:
...
else
msgbox no text found
return
Try this:
!m::
clipboard := "", MyText := "Hello World"
cmds := ["{Ctrl down}", "a", "c", "{ctrl up}"]
Loop % cmds.MaxIndex() {
Send % cmds[A_Index]
if (A_index == 2)
sleep 100
}
MsgBox % clipboard ~= "i)" MyText ? "Found" : "Not Found"