I have to test cases:
Case 1
#Include test1.ahk
::se::Stack Exchange `{backspace}
(test1.ahk is empty) then typing:
se␣ (with a space at the end) → Stack Exchange (no space at the end)
use␣ → uStack Exchange
But let say I delete the ␣{backspace} at the end or change it to
::se::Stack Exchange `{backspace}
::de::define
then it works normally again.
Case 2
#Include test1.ahk
::se::Stack Exchange
works fine, but
#IfWinActive, ahk_class SunAwtFrame
return
::se::Stack Exchange
makes se→se, i.e. nothing happens.
This is very weird, because there's nothing seems to be wrong. I can't even quarantine it, and updating AHK to the latest version or reinstalling it doesn't help. All I know is that when it happens any hotstring will behave this way. The problem started when I included this script, but even when I've exclude it this still happens. The script itself doesn't seem anything wrong too.
Also ask on Reddit.
Preventing expansion of se to trigger when you type use, is one of the reasons why I end my text expansion strings with a special character. As I maintain text expansion for three languages, I have settled on the following scheme.
text\ is the default (Dutch)
text= is used for English
text] is used for German
I also use the . in some cases to expand abbreviations.
I chose the \, = and ] signs, because they are all close to the Enter key.
Example:
Dutch:
:*:adhv\::aan de hand van
:*:bv\::bijvoorbeeld
English:
:*:am=::Account Management
:*:actm=::Active Monitoring
:*:appr=::approach
:*:art=::article
:*:ba=::business alignment
German:
:*:nrw]::Nordrhein-Westfalen
:*:ma]::Mitarbeiter
:*:fk]::Führungskräfte
Dots:
:*:adhv.::a.d.h.v.
:*:dmv.::d.m.v.
:*:ovv.::o.v.v.
As you can see, I can write adhv either with a . at the end or with a \ and they expand differently.
The * is used to overwrite the default ending characters like {Space}.
Related
I want to map two dot/period key presses to Tab key in AutoHotkey script. I tried to map similarly as its shown for remapping semicolon key - on AutoHotkey forums, but it doesn't work. I tried following:
1. `..`::Tab
2. ..::Tab
AutoHotkey gives an error
.
I tried searching on AutoHotkey Remap docs, but couldn't figure it out. The period key is the one with the greater than mark and not the number keypad period key. See this: Dot/period key
Addition info/context in response to reply by user 0x464e:
Basically, I am trying to expand Emmet style abbreviations in devtools style sub-panel since the chrome devtools team wont implement it.
I am not a fast typist, so it's a pain to type complete property names. For example, if I want to type margin-top, (see the image), Chrome autocomplete brings up margin, margin-block margin-block-end etc.
Now, for margin-top, you need to at least type margin-t to get the autocomplete to show that property.
This is the case for many very common CSS properties like margins, paddings, etc., so autocomplete isn't great.
On the other hand, if I just type mt and have Autohotkey expand to margin-top, it's much much faster, saves me much time and keeps me sane.
Basically, I have setup some hotstring in .ahk script and they work too.
However, if I press mt followed by a Tab key press, Chrome's autocomplete takes over and hotstring fails, (try once to see the problem). Instead, currently I press spacebar, or . (period) to trigger the hotstring. It works, but the problem is it leaves a space or a dot with the expanded text. [see this].
So, that's the actual reason I wanted a double period key trigger to replace Tab.
It would be great if the hotstring trigger would work with a double period key, but doesn't leave the trigger character itself and then have send Tab so as to jump to the value input of the just expanded property.
You're not really looking for a traditional remap, which is why you didn't find it from the documentation.
Remapping is just simply remapping one key to another, but you're not trying to do that. You're trying to make some action do another action.
Anyway, what you're asking is doable, but there's loads of different ways it can be achieved with difficulties varying from simple to extremely advanced & complicated.
You'll need to specify things more clearly before this can be answered properly.
Biggest questions that pop into my head right away are at least:
Should this work everywhere, or just in text input fields?
How should the original functionality of . be preserved, if at all.
(What should happen after the initial . keypress?)
Should there be some timeout between the keypresses?
Etc, this is just what I could think of right away, but surely there's more.
Anyway, for now I can give a simple implementation with a hotstring:
:*?:..::{Tab}
So this is a hotstring with the * and ? options.
I'm guessing these would probably be pretty good options for this.
So what this does, is it presses backspace twice and sends a Tab if you type ...
This should be fine for text editors, but it leaves much to be desired (the points I listed above aren't considered since I can't know what you're looking for. This is just what a default simple hotstring can offer).
Looks to me like you don't actually want the additional mapping of .. to Tab, but instead just want to update your existing hotstrings to activate immediately (without waiting for an EndChar) when the hotstring is followed by ..
Normally, you might look to the Ending Characters option to create this functionality, but since you want multiple characters to trigger this, we need to look to other options.
I will be using the example of ::mt::margin-top for my sample implementation. Extend any changes I make to these to the rest of your hotstrings in the script you screenshotted.
Here are the changes I am making to this example:
Add your .. to the end of each of your hotstrings triggers. For example ::mt::margin-top becomes ::mt..::margin-top. However, at this present, this still requires some sort of ending character to be pressed in order to proc. Let's fix that in the next step
Add the Asterisk Modifier to the hotstring. From the docs:
* (asterisk): An ending character (e.g. Space, ., or Enter) is not required to trigger the hotstring.
Final code for ::mt::margin-top example:
:*:mt..::margin-top
And extend this * insertion and .. appendation to each of your hotstrings.
Hope this helped! Lmk if you need any more help or changes.
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)
I'm trying to make filling some web-forms easier. Each form might include 100 times that tab would have to be pressed after typing a letter to be able to input the next letter to it's corresponding slot. I tried some examples, but ran in to problems when changing Windows language settings to Russian. Most of the time I will be inputting Russian letters, and if not, then just normal latin letters.
I tried following basic examples which worked for either one letter at a time or all (latin) letters at once.
#UseHook On
w::send ш{Tab}
Which outputs
ш(and one single TAB taking me to the next input)
So for some reason the characters are not correctly output from AHK.
This other example I found here and it works fine for any latin letter after a small modification:
https://autohotkey.com/board/topic/67948-detect-any-letter-key-press/
Loop 26
Hotkey, % Chr(A_Index+96),LatinLabel ;loop creating hotkeys for a-z
Return
LatinLabel:
Func(A_ThisHotkey)
Return
Func(var) {
#UseHook On
Send %var%{TAB}
}
I read that listening for all keypresses or actions would not be ideal, since this would also record mouse clicks and even movement.
So are there other alternatives googling didn't reveal to me?
Are you having problems with sending Unicode characters?
For the euro symbol I use either of:
SendInput {U+20AC}
PostMessage, 0x102, 8364, 1, Edit1, A ;WM_CHAR
The problem of ш becoming ш is due to the script file having been saved as UTF-8 without BOM. You just need to save the file as UTF-8 with BOM. AutoHotkey (as of v1.1.30.03) interprets files without a BOM as ANSI, because the default editor is Notepad, and Notepad (prior to Windows version 1903) defaults to ANSI.
The second script registers hotkeys a-z via the expression Chr(A_Index+96), which produces latin letters. Once registered, these hotkeys will activate when you press the corresponding virtual keys even if you change the keyboard layout. However, they will still send latin letters, because A_ThisHotkey is a-z.
The solution is to use the ~ hotkey modifier instead of sending the hotkey. In that case, pressing the key has whatever effect it should normally have, then the script sends Tab.
Loop 26
Hotkey % "~" Format("vk{:02x}", A_Index+64), AzKey
return
AzKey:
Send {Tab}
return
This registers hotkeys for the virtual keys vk41 - vk5A, which correspond to A - Z on layouts which contain those characters, but also work with other layouts. However, there may be some other keys which produce "letters" or other characters you want to watch for; in that case, just register additional hotkeys as needed.
Hotkey ~vkC0, AzKey
or stack the labels
vkC0::
AzKey:
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
total Emacs noob here. So right now I'm working on a fairly big LaTeX project in Emacs in which there are couple of places where I need to index some words, using the makeidx package. Because I also wanted indexed words to be bold, I created my own command \ind{} which would make the argument go bold and indexed. But right now I'm dissatisifed with this command so I'd like to change every instance of \ind{whatever} in my text by \textbf{whatever}\index{whatever by default}.
The thing is I know exactly what I want :
Go through the text, look for any instance of \ind{ and replace by \textbf{ using search-and-replace
Save the argument of \ind ("whatever" in this case) in memory
Ask me the user what should the argument of \index be. By default (by striking enter), it should be the first argument, but I can also change my mind and enter something different ("whatever by default" in this case). If there's no input (only a space " " for example) stop the program.
Write down \index{, the new argument and }.
Go to next occurance in the text.
But, alas!, I know not how to achieve this, so I need someone's help. If it should take too much time to explain how to do such a thing, would you please send me some tutorial about writing my own functions?
I hope I'm being clear, and thanks for your patience!
This approach seems vaguely unorthodox to me, but it works and seems sufficient for a one-off job...
In the replacement text for replace-regexp and query-replace-regexp (C-M-%), one newer escape sequence is \,(...), where ... can be any Lisp expression. There's a Lisp function read-from-minibuffer which reads arbitrary text typed by the user, with an optional default. Therefore:
C-M-%: Start query-replace-regexp.
\\ind{\([^}]+?\)}: The pattern to search for.
\\textbf{\1}\\index{\,(read-from-minibuffer "index content? " \1)}: The replacement text. The user will be prompted for the text to put in the braces following the \index{} element, using the original text between the braces following the \ind{} element as a default.
Note that when using query-replace-regexp, you'll have to confirm each choice by typing y after each. Use M-x replace-regexp if you want to avoid this step.
Vlad give you the LaTeX answer to your problem. An Emacs solution is the key-macro: start with
C-x (
to define a new macro, then do one step of your change, say:
C-s \ind{
<left>ex
Then copy and paste the argument in the \textbf macro... You have to be careful to move in a way that will be repeatable. Once the standard modification is done, you let the cursor after the whatever by default and end the definition by
C-x )
now C-x e will call the macro you just define, letting your cursor at the correct place to change the part you want to change You can also repeat the e to call the macro several time at once.
Why not just redefine the \ind so that it can get an optional argument?
For example:
\newcommand{\ind}[2][]{%
\def\first{#1}%
\ifx\first\empty
\textbf{#2}\index{#2}%
\else
\textbf{#2}\index{#1}%
\fi
}
This way you can use \ind{whatever} or \ind[whatever-else]{whatever}.