Autohotkey script for copying specific content inside the brackets by clicking anywhere inside these brackets - autohotkey

I want to make an Autohotkey script, so I ask you for a little help.
I work as a transcriptionist, and in my text I often have timecodes in the following format (00:00:00). I need a script what will help me to copy to clipboard a timecode in the format 00:00:00 (without brackets) by clicking to any place inside these brackets (for example Alt+LClick).
Now I use the following script, but it is hardcoded and I must click exactly in the middle of the timecode, otherwise it doesn't work:
!LButton::
Send {Click 2}
Sleep 100
Send {Right 4}{Shift Down}{Left 8}{Shift Up}
Send ^c
return
So I want an improved and more versatile script. Thank you in advance for any help.

I would use something like this if you want to select one by one.
~LButton:: ; Hold the left button to select
now := A_TickCount
While GetKeyState( "LButton", "P" )
if( A_TickCount - now > 300 ) {
; Just incremented the range
Send {AltUp}{Right 10}{Shift Down}{Left 20}{Shift Up}
Send ^c
Sleep, 100
; Filter characters between "(" and ")"
Clipboard := StrReplace( StrReplace( RegExReplace( Clipboard, "[^\)]+(\(|$)"), ")" ), "(") ; Can be better than this, but im not good with regex
Send {Right}
; Just for test
ToolTip % Clipboard
Sleep, 1000
Tooltip
}
Return
Or you can select the entire text and filter all result at once.
F1:: ; ANY HOTKEY YOU WANT
Clipboard := "Lorem Ipsum is simply (00:00:57) dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived (00:01:51) not only five centuries, but also the leap into electronic (01:23:11) typesetting, remaining essentially (00:10:23) unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum"
Clipboard := StrReplace( StrReplace( RegExReplace( Clipboard, "[^\)]+(\(|$)","`n"), ")" ), "(") ; Can be better than this, but im not good with regex
ToolTip % Clipboard
Sleep, 1000
Tooltip
Return

Related

Looking for text character counting functionality in ahk

Is there any text counting functionality in ahk?
I want to make an character counter where, if i press ctrl+alt+-, an input box will open. And the number of characters used in the variable‘s value will be counted.
You can start with:
<^<!-::
InputBox, Text1, Count, Paste the text in the text box to count the number of characters it has, and find things in that text
MsgBox text:You typed %Text1%.`nCharacters:
return
any answers? thanks.
The StrLen() function retrieves the count of how many characters are in a string.
<^<!-::
InputBox, Text1, Count, Paste the text in the text box to count the number of characters it has, and find things in that text
if ErrorLevel
return
number_of_chars := StrLen(Text1)
MsgBox text:You typed %Text1%.`nCharacters:%number_of_chars%
return

autohotkey text replacement with variable

I am trying to figure out a way to do text replacement with a variable if possible.
Basically let's say I have a string: The Color is Red
I can say ::color::The Color is Red which will work, but now what if I want to be able to specify the color on demand. So if I typed color blue it would print out The Color is Blue instead.
Is there a way to do that? Or will I have to define all possible variations of my sentence in my script.
You can use a parsing Loop (or a For Loop in an array) and the Hotstring() function to create the hotstrings dynamically:
colors := "Blue,Red,White"
Loop, parse, colors, `,
Hotstring(":*:" "color " A_Loopfield, "The Color is " A_Loopfield, On)
The above code has to be placed in the auto-execute section (top of the script, before the first hotkey, hotstring or return) otherwise the script can't create the hotstrings.

How to prevent line breaks (general)

I'm writing a text on C++. But often the line breaks after the first "+", so I get C+
+
This is just an example. How can I prevent line breaking of arbitrary parts in my odt doc?
There is no formatting option at the moment
Use the Unicode Character U+2060. Insert it an every point the line breaks, but it shouldn't. It glues two parts together.
Example for "C++" ( | represents the text cursor )
C|++
Press Ctrl+Shift+U
u will appear on the screen
Type in 2060
Press Enter
Now the line won't break between C and +.
Move cursor: C+|+
repeat process

Eliminating double, triple, quadruple, etc. spaces in MS Word

I receive a lot of text files like this
120
1
230
1.3
3
13240
7
In addition, there is some regular text there too (single space between the words). So I would like to come up with a way to automatically "search and replace" two, three, four, five, etc. spaces (all but single spaces) so that the above numbers no longer have any spaces in front of them. Any thoughts? Maybe a macro would help?
You don't need a macro, actually, this can be done simply with the Find and Replace tool.
Open the Find and Replace dialog box (control+H by default).
If the Search Options section is not currently displayed, press the "More > >" button to display it.
In the Search Options section, check the "Use wildcards" checkbox.
In the "Find what:" field, enter a single space followed by {2,} .
In the "Replace with:" field, either leave it blank to remove the leading spaces entirely or put a single space to replace all repeated spaces with a single one.
Press the Replace All button.
Note that if you choose to remove leading spaces entirely, this may backfire if you have any lines beginning with just a single space; these will still have the space there, while the ones that used to have multiple spaces at the beginning will have them all removed.

AHK Want to type number and have text expand around it so I can change number but text remains

I want to accomplish the following.
I want to write 2450 ddu1, where 2450 = the number and ddu1 = the trigger.
Writing the above would make it look like this:
Door delivery SEK 2450, based on your specified weight measurements.
The thing is that the numbers vary and so I need to be able to write the correct number and then the "text expansion phrase" to trigger the text.
I can expand text but I can't do it with my number remaining in the middle of the expanded text.
Thank you kindly for your help and effort.
There's no native support for dynamic hotstrings in AHK. But there's a great library that should fit your needs.
Check out Hotstrings, by Menixator.
Download that lib and try running this code:
#include Hotstring.ahk
; Listens for 1 or more digits, followed by "ddu1"
Hotstring("(\d+)\s+ddu1", "printPrice", 3)
return
; Prints a string with the digit in it
printPrice(param){
str_s := "Door delivery SEK "
str_e := ", based on your specified weight measurements."
out_s := str_s . param.value(1) . str_e
SendInput, %out_s%
}
Esc::ExitApp
It's triggered by typing one or more digits, followed by a space, followed by ddu1.
For example: 1 ddu1, 512 ddu1, 23123516161612 ddu1.