advance hotstrings in autohotkey - autohotkey

I found this working autohotkey (ahk) code from the website https://jacksautohotkeyblog.wordpress.com/2015/10/22/how-to-turn-autohotkey-hotstring-autocorrect-pop-up-menus-into-a-function-part-5-beginning-hotstrings/ .
::agin::
TextMenu("again,a gin,aging")
Return
::duh::
TextMenu("what,huh,you're joking")
Return
TextMenu(TextOptions)
{
StringSplit, MenuItems, TextOptions , `,
Loop %MenuItems0%
{
Item := MenuItems%A_Index%
Menu, MyMenu, add, %Item%, MenuAction
}
Menu, MyMenu, Show
Menu, MyMenu, DeleteAll ;Moved from MenuAction:
}
MenuAction:
SendInput %A_ThisMenuItem%{Raw}%A_EndChar%
Return
This is a hotstring script with menu. For example when I type agin I get a many with three options (again,a gin,aging) to choose. Now I want to write it something like this:
agin=again,a gin,aging
duh=what,huh,you're joking
qwe=qwe,qww,ere
Because I have a lot of hotstrings.

As time has passed, in the most recent version of AHK it became possible to do!
Use option x to allow expressions in the oneliner.
Either as :x:...:: OR as a group option above all lines: #Hotstring x
:x:agin::TextMenu("again,a gin,aging")

As nice as it would be, unlike AutoHotkey Hotkeys, I don't believe you can put anything other than replacement text on the same line of an AutoHotkey Hotstring. In other words,
::agin::TextMenu("again,a gin,aging")
would not work while,
::agin::
TextMenu("again,a gin,aging")
Return
does. It is a few more characters long, but not overwhelming.

Related

HotKey multiple characters

Is it possible to define an AutoHotKey HotKey which require multiple characters to fire ?
Example: if I write the AHK script
^j::
Send, my test
return
The Hotkey Control j fires off the string "my test"
What if I wanted to require Control jBAS to fire off the script ...in this case the letters BAS following the Control j ? From the examples I have seen, HotKey does not seem to allow this ...I can accomplish this with a HotString ...problem with HotString is that you must hit Enter and then the original String is replaced with the new HotString definition.
Heres an option:
^j::
Input, matchVal, C L3,, BAS
if (matchVal=="BAS") {
Send, mytest
}
Return
Check out https://www.autohotkey.com/docs/commands/Input.htm for further data and options.

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

(AHK) Creating variable hotkeys that gets the key names from a 2 char file name of a script

I'm trying to make something for our employees to use so that they dont have to alter the script itself to define hotkeys. This may only work for hotkeys which can be defined by a single character, but that's fine, as there are so many combinations that can be made with them, and they can be very easy to remember. The script would look only at 2 character AHK files (or 6 if you must include the extension) in the working directory. And the variables it would search for could be defined with RegEx so for the first hotkey, it would look like ^. and then second would look like .(?=.) Once a match is found, it would simply launch that matched file. Has something like this been done before? It seems so simple but I can't seem to find anything on it.
Edit: Elliot brought this to my attention: http://autohotkey.com/board/topic/60630-easy-editmanage-hotkeyshotstrings-plugin-ahk-l/
It's a neat script manager, and very useful, but it's not what I'm looking for.
I dont not want an additional interface. I want to be able to change the hotkeys by using the filename.
Based on the answer of Forvin. Added the execution of the corresponding ahk script.
#Persistent
SetTimer, FindNewHotkeys, 2000
FindNewHotkeys:
Loop, %A_ScriptDir%\*
{
RegExMatch(A_LoopFileName, "^(.)(.).ahk$", hk)
If (hk)
{
Hotkey, ~%hk1% & ~%hk2%, HotkeyLabel
}
}
Return
HotkeyLabel:
RegExMatch(A_ThisHotkey, "~(.) & ~(.)", hk)
run, %hk1%%hk2%.ahk
Return
#Persistent
SetTimer, FindNewHotkeys, 2000
FindNewHotkeys:
Loop, %A_ScriptDir%\*
{
RegExMatch(A_LoopFileName, "^(.)(.).ahk$", hk)
If (hk)
Hotkey, ~%hk1% & ~%hk2%, HotkeyLabel
}
Return
HotkeyLabel:
MsgBox, A hotkey has been pressed!
Return

autohotkey long text and in a virtual machine

So I'm trying to learn autohotkey scripts and the documentation is lacking at best. First, can authotkey read commands and perform actions and such inside a virtual machine? I have a windows host and a linux virtual machine running eclipse. I'd like to get a hostring (or a keyboard macro, either is fine) to put in some long (10+ lines) of text. Can that actually work in a VM or do I have to run autohotkey inside the VM for it to work?
As for implementing this, I have 2 problems. First, how do I display multiple lines of text from a keyboard macro? I know about the Send command, but I haven't figured out how that works. I have this:
:*:insert::
(
Text to
insert
goes here
and more here
)
And this works fine except in notepad++, it inserts consecutively more tabs, so it will look like
Text to
insert
goes here
and more goes here
And so in my many line macro, by the end it's several pages scrolled off the screen.
As for keyboard macro, changing the above to
#c::
Send{Raw} (
stuf
to send
)
Return
This gives syntax errors and I have no idea what the correct way of doing that would be. Should I just stick with using hotstrings?
You could try to modify the clipboard and use control + v to paste it into the proper place.
Try:
#c::
{
clipboard := "yourtext`nMultiline`nYet another line"
send, {control down}v{control up}
return
}
The first 'insert' hotstring is correct,
however, you would get the same result that you describe,
if you performed manually, the keypresses that the hotstring is sending.
To get the output you want,
you need to change these two settings:
Settings, Preferences...,
Auto-Completion,
untick: Enable auto-completion on each input
Settings, Preferences...,
MISC.,
untick: Auto-indent
the '#c' hotstring is amended below:
#c::
Send {Raw}
(
stuf
to send
)
Return

Autohotkey to select text under cursor?

Is it possible to select text under cursor using Autohotkey specifically, using a mouse and a key combination. e.g. I specifically want to just do a Ctrl-click on any word in IE/FF/Foxit Reader and a webpage with first Google search result opens up.
Thank you.
Yes it is possible...
The easiest way is to set Ctrl+LButton to double click (which selects the current word under the cursor) copy the word to the clipboard and then use google with the parameters "q=" for the search term and "btnI=I'm+Feeling+Lucky" for using the "I'm Feeling Lucky" function.
It would look like this:
^LButton::
Send, {LButton 2}^c
Run, http://www.google.com/search?&q=%clipboard%&btnI=I'm+Feeling+Lucky
return
This would work in most cases without issues, the issue comes when selecting words like:
53°C
Jhon's
test%s
and others, because double clicking them only selects the first part of the text before the symbols.
So as long as you are double clicking normal words this should work fine.