error with use get

Get help with using AutoHotkey (v2 or newer) and its commands and hotkeys
dougbush
Posts: 1
Joined: 26 Nov 2022, 06:50

error with use get

Post by dougbush » 26 Nov 2022, 07:20

I want to use ctrl+shift+k to input the kotlin code block of markdown style,
so, I use

Code: Select all

^+k::
{
    Send "``````kotlin{enter}``````"
}
#HotIf
but the result is

Code: Select all

```kotlin
```
```
```
When I replace

Code: Select all

Send "``````kotlin{enter}``````"
with

Code: Select all

Send "````kotlin{enter}````"
, the result is

Code: Select all

``kotlin
``
,
the actual result doesn't match documentation, what should I do to work it.
I have attempted the version of 2.0-beta10 and 2.0-rc1. The result is what I mentioned above

User avatar
haichen
Posts: 631
Joined: 09 Feb 2014, 08:24

Re: error with use get

Post by haichen » 26 Nov 2022, 09:49

` is a special sign. With the keyboard it appears only after entering another character. This is exactly why the first three characters are shown correctly.
Try this:

Code: Select all

^+k::
{
    Send  "`````` kotlin {enter}`````` "
}
Result:
```kotlin
```

gregster
Posts: 9029
Joined: 30 Sep 2013, 06:48

Re: error with use get

Post by gregster » 26 Nov 2022, 10:56

haichen wrote:
26 Nov 2022, 09:49
` is a special sign. With the keyboard it appears only after entering another character. This is exactly why the first three characters are shown correctly.
To clarify a little, yes, it's special in general - because it's AHK's escape character, but that has nothing to do with the used keyboard layout.

Yes, ` is also a "dead key" on many keyboard layouts, but - for example - on the basic US-EN layout, ` is not "dead", but a regular key. Yet, that doesn't change AHK's escape syntax, (although it gets processed differently; it's true that there is an even/odd difference for layouts with dead keys, similar to the manual typing of that key).

Spoiler

@dougbush, it is actually documented that you need to use two consecutive `s to get one literal `, which explains your findings that you only got three backticks, not six: https://lexikos.github.io/v2/docs/misc/EscapeChar.htm
Btw, is ` a dead key on your keyboard layout? My guess is that this just an escape character question, not a dead key problem.
Last edited by gregster on 26 Nov 2022, 13:34, edited 1 time in total.

User avatar
haichen
Posts: 631
Joined: 09 Feb 2014, 08:24

Re: error with use get

Post by haichen » 26 Nov 2022, 11:29

Thank you for this further explanation.

gregster
Posts: 9029
Joined: 30 Sep 2013, 06:48

Re: error with use get

Post by gregster » 26 Nov 2022, 11:49

gregster wrote:
26 Nov 2022, 10:56
@dougbush, it is actually documented that you need to use two consecutive `s for one literal `, which explains your findings: https://lexikos.github.io/v2/docs/misc/EscapeChar.htm
Since I suspect that you want 6 consecutive literal `s (twice) for markdown, you could try:

Code: Select all

Send "{`` 6}kotlin{enter}{`` 6}"
(spares some typing... and counting)

safetycar
Posts: 435
Joined: 12 Aug 2017, 04:27

Re: error with use get

Post by safetycar » 26 Nov 2022, 12:22

It is special in ahk, but it is also especial relating some regional configurations.

For example, let's say Spanish, typing directly with no ahk involved, a single key press on the backtick won't display anything until the second key press.
It will wait until the next key press to know how it has to be interpreted, pressing backtick before "a" would write à, but for "b" it would become `b,

A single backtick can be written with a space after the first backtick, but another way for the backtick can appear is pressing twice the backtick, in which case it appears twice ``.

This even/odd combination of presses have at least some similarities with what OP is describing, but I am unsure if it's related or not.

I found this link too https://en.wikipedia.org/wiki/Dead_key

gregster
Posts: 9029
Joined: 30 Sep 2013, 06:48

Re: error with use get

Post by gregster » 26 Nov 2022, 12:30

Sure, but the fact that it is a dead key (on some/many layouts) has nothing to do with its original choice as AHK's escape character. That's just a coincidence, I would suppose, which of course rather complicates things on dead key layouts when sending an odd number of literal `s. :problem: Then, an additional space (or other character) is required, except for text mode which could probably provide a layout-independent solution for inserting literal backticks.

Since the OP wants 6 literal consecutive ones (if I understand correctly), Send "{`` 6}" should even work with a dead key. Otherwise, for an odd number like 1 or 5, I would probalbly add a trailing space.

Not sure if Chris Mallett even cared much about dead keys when he started AHK development, as there are none on the standard US layout.
Also, iirc, there have been a few changes or fixes re dead key behaviour over the years (at least in v1, which surely were reflected in the contemporary v2 versions).

edited

Post Reply

Return to “Ask for Help (v2)”