Capital letter following an em dash

Get help with using AutoHotkey and its commands and hotkeys
JPh1
Posts: 22
Joined: 18 Jan 2018, 22:06

Capital letter following an em dash

27 Jun 2018, 13:35

In order to write dialogs that start with an em dash (long dash), I create an em dash from 2 en dashes:
::--::—

Following that I'd like the first letter to be capitalized, as in

— I didn't know...

Is there a simple way to do that?
User avatar
gregster
Posts: 1497
Joined: 30 Sep 2013, 06:48

Re: Capital letter following an em dash

27 Jun 2018, 14:37

Well, the simplest approach I would imagine like this:

Code: Select all

::--::
SendInput —%A_Space%
Input, char, L1
SendInput +%char%
return
It adds already a space after (in order too keep the approach simple). But there is most probably a number of alternative approaches.
JPh1
Posts: 22
Joined: 18 Jan 2018, 22:06

Re: Capital letter following an em dash

27 Jun 2018, 14:59

It works beautifully. Thanks a bunch.
JPh1
Posts: 22
Joined: 18 Jan 2018, 22:06

Re: Capital letter following an em dash

12 Jul 2018, 10:45

As it turns out, there are times when my keyboard freezes as a result of this code. It stays frozen for several minutes during which I can't type anything... Can you see the reason why and suggest a change or another code?
User avatar
gregster
Posts: 1497
Joined: 30 Sep 2013, 06:48

Re: Capital letter following an em dash

12 Jul 2018, 17:00

Well, i haven't really tested it much. Let me see if I can reproduce the problem... can you add some details about the circumstances of the freeze?. Does it happen after typing -- or rather randomly? Do you use other scripts that might interfere?
The more details you can give about the circumstances about the freeze and de-freeze, the better... also which AHK and Windows version are you using?
JPh1
Posts: 22
Joined: 18 Jan 2018, 22:06

Re: Capital letter following an em dash

12 Jul 2018, 17:25

I'm using AHK 1.1.22.4 on Windows 8.

I'm not able to reproduce the problem. It happens after I type -- (the string that your code converts to m dash followed by capitalization), but most of the time there is no problem with it.

I thought about possible interference with a code (obtained from this site) to capitalize sentences followed by punctuation marks and a new paragraph (see below).

When I hit return and type --, it becomes _-. I therefore added a code similar to yours but with _- instead of --.

Finally I only use those codes for a number of programs that are in Mygroup.

My script is therefore:

#IfWinActive ahk_group Mygroup
; Capitalization following punctuation and carriage return
~.::
~!::
~?::
KeyWait, Shift
input, w, L1 t5 v, {Escape}
if(w != A_Space && w !="`n")
return
SendEvent, {Shift Down}
input, w, L1 t5 V, {Escape}{BackSpace} ; Limit to 1 character, timeout after 5 seconds
SendEvent, {Shift Up}
return

; Capitalization following -- and _-
::--::
SendInput —%A_Space%
Input, char, L1
SendInput +%char%
return

::_-::
SendInput —%A_Space%
Input, char, L1
SendInput +%char%
return
#IfWinActive

Most of time it all works fine. But every now and then the keyboard freezes. Thanks for taking the time to look at this.
User avatar
gregster
Posts: 1497
Joined: 30 Sep 2013, 06:48

Re: Capital letter following an em dash

12 Jul 2018, 17:45

Perhaps the Input command is stuck somehow (although yet I am not sure why). I would first try to add a timeout there in the last two hostrings, too, something like L1 T3 - in this case timeout would be 3 seconds...
JPh1
Posts: 22
Joined: 18 Jan 2018, 22:06

Re: Capital letter following an em dash

12 Jul 2018, 17:55

I just did that. One problem I see is that the word following -- is capitalized but in case it's a hotstring (I have hundreds of them) it's not replaced with its new string. No big deal for now. Let's see if this solves the freezing problem.

Return to “Ask For Help”

Who is online

Users browsing this forum: Albireo, Bing [Bot], Helgef, ivanstera, newbieforever and 36 guests