Remove the space in the end of text - autohotkey

I'm just starting to learn to use Autohotkey, mostly for text expansion, ie when I type goo and it will become www.google.com. Problem is, in Windows, it always leaves a space in the end and that's annoying. What can I do to avoid that?
I tried added {bs} and {left 1} to the script but it moves the cursor before the last character eg www.google.com

The reason there is a space at the end is because you're pressing space to end your hotstring. If you use the O option, it will omit the ending character. Try this:
:O:goo::www.google.com
More information can be found here in the official help docs: https://www.autohotkey.com/docs/Hotstrings.htm

Found the answer myself! My original code syntax was like this...
::goo ::www.google.com
Doing so leaves a space in the end
I changed it to...
::goo ::
Send, www.google.com
return

Another option is to use :*:goo::www.google.com
The asterisk means that the hotstring will be activated without waiting for you to end the hotstring (though in this case, typing 'good' would pose a problem)

Related

How to keep spaces at the end of AutoHotKey snippets?

How to keep spaces at the end of AutoHotKey snippets? No matter how many I place in my ahk file, no spaces are present on execution.
Add {space} at the end of the command,
e.g.
Send myName{space}
Send abc{space 2} ; add 2 spaces after abc
Depends on your needs, but usually you can use the built-in variable %A_Space% for that.
Alternatively, you can add an escape after your space like this:
:*: ive :: I've `

How to use a phrase as HotString in AutoHotkey - including spaces in HotString

Is there a way to include a space in the HotString and still have the space trigger the HotString replacement? For example:
::_u_::_you_ <--where the underscores are actually space chars
or
:*:_fo_r::_for_ <--where the underscores are actually space chars
so if I typed
StackOverflow is a great place fo ranswers!
it would be changed to
StackOverflow is a great place for answers!
I'm looking for a way to define a phrase as the hotstring really.
Strange. I tried escaping with `s but that didn't work. The docs say two things:
To send an extra space or tab after a replacement, include the space or tab at the end of the replacement but make the last character an accent/backtick (`). For example:
:*:btw::By the way `
and
Spaces and tabs are treated literally within hotstring definitions. For example, the following would produce two different results: ::btw::by the way and ::btw:: by the way
So, I would think this should work:
:*: fo r:: for `
That works in notepad, but only if I try it at the start of a line. Mid-sentence it fails.
You may be forced to use one of the user-created dynamic regex hotstring libraries.
Using this library, this works:
#include Hotstring.ahk
Hotstring(" fo r", " for ")
edit:
I asked on the AHK forums, and the ? option should do it:
:*?: fo r:: for `
This will work.
:*: fo r::
SetKeyDelay, -1
Send for{space}
return

Autohotkey, putting "D89dl" at the end of a sentence doesn't work as intended

I have a Autohotkey script that puts "D89dl" at the end of a sentence everytime I press Enter, but using it with a AutoCorrect script it doesn't work as it should. Let's say you type "dont", it then would look like this "don't" instead of "don't.". Something is blocking it but I'm not sure what it is, I've been trying for months now.
Here are the scripts:
enter::
send,D89dl{Enter}
Return
#Hotstring EndChars -()[]{}:;'"/\,.?!`n `t
::dont::don't
I would be VERY thankful if anyone of you helps me with this.
Overall, do you know any other way instead of Autohotkey that puts "D89dl" at the end of a sentence?
The easiest solution seems to be to use the :*: mode, which will trigger everytime the misspelled word is typed, without the need for Hotstring EndChars:
:*:dont::don't
Instead of using Enter, I suggest you use a special combination of keys that enter the string D89dl and then press Enter. Use a modifier like ctrl or alt and another key. The reasoning is that the key Enter has very important functionality and should not be changed. Pressing that special combination is appropriate, given the very special function it does.
It's a bit hacky, but it should do the job (given that by "end of sentence" you actually meant pressing "Enter"):
~enter::
Sleep, 100
SendInput, {BS}D89dl{Enter}
Return
#Hotstring EndChars -()[]{}:;'"/\,.?!`n `t
::dont::don't

SendInput %userInput% causes my computer to malfunction oddly

SendInput %userInput% causes my computer to do very weird stuff. Sometimes it logs off, sometimes my arrows of the keyboard get disabled, sometimes it runs cmd in windows an infinite times...
UPDATE:
this is the thing that gets inputed in the command line and runs:
runas /user:administrator cmd
UPDATE:
I think I almost got the problem, as such I edited the question to leave out what I deem to be irrelevant now.
When SendInput is happening, and the user is still inputting data in the keyboard, such as pressing the win-key, then this can cause the system to log off because win-key + l is a shortcut for that. Likewise must be for all the other things that are happening. Another observation is that SendInput skips certain characters, like {enter} etc. It only processes them at the end, when all the regular characters are put into place. I notice that at the end, SendInput is still busy doing stuff, perhaps some exotic characters it delayed till the end. Because the user think the output is complete, he ends up pressing the shortcut key again which in combination with the current sendInput is causing the system to crash.
UPDATE:
It also goes bezerk if there is a "!" to be send with SendInput.
This is one string I pasted to the copyboard:
dsjkfhjdsfsjdh!!!!!!!!!!!####################$$$$$$$$$$$%%%%%%%%%^^^^^^^^^^^^^&&&&&&&&&&&&&*****(((((((((())))))))))))____++++++++++++++++=======------------000000000000000099999988888.
But the output is WITHOUT the exclamation marks. Like this:
dsjkfhjdsfsjdh#######$$$$$$$$$$%%%%%%%%%&&&&&&&&&&&&*****(((((((((())))))))))))____+======------------000000000000000099999988888.
Why is that? Are there any other characters? Exclamation marks are important I feel, and I don't want to remove them. Are there any workarounds?
UPDATE:
It is more complicated than that. When I copy paste the above characters WITHOUT the exclamation marks, it still does weird stuff.
Here is some of the code that eventually userInput combines and sends away with SendInput:
StringReplace, contents, save_selection, ``, ````, All ; Do this replacement first to avoid interfering with the others below.
StringReplace, contents, contents, `r`n, %A_SPACE%, All ; Using `r works better than `n in MS Word, etc.
StringReplace, contents, contents, `;, ```;, All
;* loc_title origanally contains browser specification. Remove it.
StringGetPos, pos_delim, loc_title, - , R
length := StrLen(loc_title)
count := length - pos_delim
StringTrimRight, loc_title, loc_title, count
You could use sendraw instead of sendinput.
Here is what the docs say:
Raw mode: The SendRaw command interprets all characters literally
rather than translating {Enter} to an ENTER keystroke, ^c to
Control-C, etc. However, the normal rules for escape sequences,
variable references and expressions still apply since these are
processed before the command executes. To use raw mode with SendInput,
SendPlay, or SendEvent, write {Raw} as the first item in the string;
for example: SendInput {Raw}abc.
Then you don't have to worry about the ! or other control modifiers.
The reason that the exclamation mark character is an issue is because SendInput treats it as a code to press the Alt key.
There are several similar codes:
^ = Ctrl
+ = Shift
# = Windows key
You can find the others listed in the documentation for SendInput.
It seems like you want to send the raw text and not have SendInput look for these codes. You should be able to put {Raw} at the beginning of the userinput variable and it will ignore any codes in the rest of the characters.
If it is typing too slowly, you could put SetKeyDelay,-1 in your script to remove the key sending delay.
A good workaround that I found was to avoid SendInput altogether. Rather use the clipboard to copy the string inside, to then paste it on your screen. It works flawlessly, and is a billion times faster. Why would a person utilize SendInput in the first place? However, the actual question still is standing, why does SendInput behave so strangely? What is inside that string: %userInput% that causes my system to crash? How can I find out?

Creating an AutoHotkey entry that ends in a colon

I have a weird typo that I keep making over and over, and instead of actually working on my typing skills, I want to edit my AutoHotkey script to compensate for this.
sometimes when I type the capital I I hit the : button and type "I:" and I want AHK to replace that string with just the letter I.
I already have a similar Hotkey
::custoemr::customer
But since the string uses a colon, I am having difficulty getting it to do what I want.
Any I:deas? (See?)
Yes! It is a work around, but it works...
#Hotstring EndChars :
:?O:I::I
Anything below the line #Hotstring EndChars : will use the : as EndCharacter.
Not sure if this will work for you it changes I:Space into I, but it requires the Space.
:*:I`: ::I ; The `is the escape but with 3 ::: AutoHotKey still get's confused