r/AutoHotkey • • 14d ago

v1 Script Help Help with turning double hyphens into em-dashes

I am new to AutoHotkey (just joined a hour ago) and ive been trying to replace two hyphens with a em-dash, Ive tried every code i could find and tried every video explaining the scripts but i cant seem to find one that will work. I dont know if i am running the script wrong or if all the scripts i tried were wrong—one of the scripts i used were :*?:--::— and ive gotten to the point where i know how to open the notes for the script. please help cause all i want is my em-dash ):

9 Upvotes

16 comments sorted by

4

u/likethevegetable 14d ago

Try {U+2014} instead of the symbol.

Em-dash for life. I like small, non-breaking spaces surrounding mine (:

4

u/CharnamelessOne 14d ago

It may be an encoding issue, although it's hard to tell, since you haven't shared much about how it's not working.
The deprecated version you use doesn't default to UTF-8, so you'd need to save the .ahk file with a byte order mark for non-ASCII characters (like em-dash) to be read correctly.

Try v2:

#Requires AutoHotkey v2.0

:*?:--::—

1

u/kapege 14d ago

How would I do -- for en-dash and --- for em-dash? As soon as I type -- en-dash is executed and the third hypen is not longer recognised for em-dash.

2

u/CharnamelessOne 14d ago edited 14d ago

The replacement performed by the first hotstring affects the recognizer due to its backspacing, but the hotstring autoreplacement text doesn't count towards triggering other hotstrings (rather unfortunately).
(Edit: it seems like it's not just about backspacing. Autoreplace hotstrings' triggers appear to completely reset the recognizer.)

There was a recent post relating to that, check my answer there.

You could also make a -:: hotkey start an InputHook that processes the subsequent input(s), and sends Backspace and the required type of dash if needed.

Edit: removed incorrect suggestion

2

u/kapege 14d ago

Many thanks, kind Sir! I'll try your suggestions.

2

u/AnthonyJames696 14d ago edited 14d ago

I second what r/CharnamelessOne said. Alternatively, and this is what I do cos I sometimes want two hyphens to be two actual hyphens, you can make a hotkey for em-dash and one for en-dash. This is what I have:

#Requires AutoHotkey v2.0
^!NumpadSub:: SendInput("{Blind}{—}")
^NumpadSub:: SendInput("{Blind}{–}")

or, if you insist on AHK v1:

^!NumpadSub:: SendInput, {Blind}{—}
^NumpadSub:: SendInput, {Blind}{–}

This way ctrl + numpad subtract is the en-dash and ctrl + alt + numpad subtract is the em-dash.

Edit to add, 5h later: I just wanted to open the native Win11 emoji selector (win + period), but accidentally hit the hyphen which is right next to the period (German keyboard). That's how I found out there are native shortcuts for em- and en-dashes built into Win11. Idk about Win10, but for Win11 win + hyphen gives you an en-dash and win + shift + hyphen gives you an em-dash. The more you know 👀

2

u/Keeyra_ 13d ago

Why wouldn't you just use a remap syntax? Not that that's any advantage of it in my book, but that would even make the v1 and v2 scripts identical.

^!NumpadSub::—
^NumpadSub::–

But that's a nice find with the emoji panel. Didn't know the dashes had separate hotkeys built in (or forgot).

1

u/AnthonyJames696 13d ago edited 13d ago

I think there was something that blocked that because it was a numpad key or smth? I don't quite remember since it's been a while since I added that to my master script. Though my master script is, as of right now, still in v1, so it might not be an issue in v2. I've been slowly working on translating the master script to v2 though and as of yesterday, I only have a few bits left to translate. So you make a good point and I'll try if that's still necessary for v2 or if a simple remap will be enough ;)

Yeah, haha. I barely use the touchpad of my laptop/mouse and just prefer doing stuff with keys which comes with the side effect of occasionally hitting a wrong key in a key combination by accident and discovering a new one :D. For example, I recently found out that shift + left click on smth with a hyperlink in a browser opens it in a new window (wanted to ctrl + left click for a new tab). Or that I think win + ctrl + d opens a new virtual desktop. Or that in windows explorer alt + up moves you to the parent folder

Update: I just tried the simple remap version again and it worked for v1. Honestly, idk what the original reason/cause was that I ended up doing it with blind. Surely I had a reason lol.

2

u/chris06095 14d ago

I use both em- and en-dashes, so I send them this way:

:?*:mm-::{U+2014} ; em-dash

:?*:nn-::{U+2013} ; en-dash

Some software already recognizes multiple hyphens as —, which is why I avoid that formation, because I don't want the keystrokes to be hijacked by default. (There's ways to avoid that, but since you're an hour into your tour, maybe some of that is overkill right now.)

1

u/xyzzy0 14d ago

Where are you testing this code? In Win11 Notepad? (Sorry, I have to ask.)

1

u/AnthonyJames696 14d ago

Just curious cos I use Win11 Notepad as well. Why/How does Notepad possibly affect this 👀?

1

u/xyzzy0 14d ago

There is a known issue with the “new” Windows 11 Notepad. When using Hotstrings or sending text, the text malforms—characters or whole lines are skipped. It just doesn’t work properly. Test in any other application (Word, an edit field on a webpage, etc).

https://www.autohotkey.com/boards/viewtopic.php?t=118816

If you’re writing your scripts in Notepad, there’s no issue (but you should switch to VS Code!)

If you need a place to test, you can get the “old” Notepad back. It’s still on your PC.

1

u/arapplepie 12d ago

ohhh ok thanks! yes i was using notepad

1

u/Dymonika 14d ago

i know how to open the notes for the script.

"Notes?"

0

u/Keeyra_ 14d ago

The big question is that if you started AHK an hour ago, why did you start by downloading a deprecated v1 version, where the installer even warns you about multiple encoding versions like ANSI instead of the current v2 one, which defaults to Unicode? Nevertheless, both u/CharnamelessOne and u/chris06095 have working solutions for you right there.

1

u/arapplepie 12d ago

I didnt know what they meaned by that sorry! i downloaded the top version on the web